I'm working on a project with EntityFramework and MVC, and I keep getting this error :
The model backing the 'EFDbContext' context has changed since the database was created.
The problem is that there are no migration pending (I've tried to delete/recreate the database, but I still get the error)
I've read several posts on the Web that let me think that I'm not the only one who struggle with this error.
Please find more details below. Any help will be welcome to understand the situation and fix it.
I've three projects in my solution:
I'm trying keep it "Code First" (I would like to work in the code only, and let EF deal with the database)
I've deleted the database and the "Migrations" folder in the Core project to start "from scratch".
I run the GUI.MVC project : I get no error while browsing and the database is created "on-the-fly" when I access to the views based on it.
However, if I run the GUI.Console project, I get the error.
I open the Package Manager Console with the Core project as default project (in the dropdown list) and the MVC project (with the connexionstring in the Web.config) as startup project
I run the command
Enable-Migrations -EnableAutomaticMigrations. A new folder "Migrations" is created in the Core project. The situation is the same : the MVC project works, the Console doesn't.
I run the command
Update-Database, and get :
No pending explicit migrations. Applying automatic migration: 201408071410203_AutomaticMigration. Running Seed method. Now, the MVC project no longer works : I get the error (The model backing...) when I try to access the data. However, the Console project is now working!
If I re-run the command
Update-Database, I get
No pending explicit migrations. Running Seed method. And I still get the error in the MVC project, and the Console project is working.
Visual Studio 2013 Update 2
Thanks a lot !
You can turn on debugger, i would assume the exception will stop at one the dbcontext or dbset, and inspect the dbcontext or dbset variable, find its dbcontext object , and inspect base -> Database -> connectionstring property, then you should see which database it is complaining. Looks like you are deleting the wrong database.