SetInitializer is not running, but EF is still trying to create a database

Running MVC4 project with EF5.0

When developing my model, EF created a new db at each model change and seeding with data samples. The model design is now complete, and db is filled with live data, so I commented out the line responsible for creating db:

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

But when I try to compile, I click:

It is not possible to create xx because it already exists. Change the file path or file name and retry the operation. CREATE DATABASE failed. Some of the listed file names cannot be created. Check related errors.

I even excluded the file using the Seed method from the project, so "DropCreateDatabaseIfModelChanges" cannot be called - presumably.

+4
source share
1 answer

You can disable the default initializer

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

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

+2
source

Source: https://habr.com/ru/post/1447481/


All Articles