justSteve
justSteve

Reputation: 5524

Not running SetInitializer but EF is still trying to CreateDatabase

Running an MVC4 project with EF5.0

While developing my model, EF was creating a new db at each model change and seeding with sample data. Model design is now done and the db is populated with live data so I've commented the line responsible for creating the db:

//System.Data.Entity.Database.SetInitializer(new SampleData());

But when attempting to compile I'm hitting:

Cannot create xx because it already exists. Change the file path or the file name, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

I've even excluded the file with the Seed method from the project so 'DropCreateDatabaseIfModelChanges' can't be invoked - supposedly.

Upvotes: 4

Views: 1140

Answers (1)

ckal
ckal

Reputation: 3570

You can disable the default initializer

System.Data.Entity.Database.SetInitializer<MyContextName>(null); 

There is also a web.config way: http://msdn.microsoft.com/en-US/data/jj556606

Upvotes: 2

Related Questions