Entity Framework : The model backing the 'EFDbContext' context has changed since the database was created

asp.net-mvc c# dbcontext entity-framework entity-framework-6

Question

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.

Project details

I've three projects in my solution:

  • Core : Models and mappings with the database
  • GUI.MVC : A web project (using the models from the Core)
  • GUI.Console : A non-web project (using the same models)

I'm trying keep it "Code First" (I would like to work in the code only, and let EF deal with the database)

Step-by-step

  1. I've deleted the database and the "Migrations" folder in the Core project to start "from scratch".

  2. 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.

  3. However, if I run the GUI.Console project, I get the error.

  4. 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

  5. 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.

  6. 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!

  7. 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.

Configuration

Nuget packages

  • Entity Framework 6.1.1
  • ASP.NET MVC 5.1.2

Visual Studio 2013 Update 2

Thanks a lot !

1
1
8/7/2014 2:40:17 PM

Popular Answer

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.

0
8/13/2014 10:46:50 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow