Entity Framework bug? "Context changed" Error, even when not

asp.net-mvc asp.net-mvc-4 ef-migrations entity-framework entity-framework-6


I have gotten myself into an odd Groundhog Day scenario with an MVC application of mine.
Unless I apply my workaround (Later in this question) each time I debug the application I'm presented with this error:

The model backing the 'UsersContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

I have not changed the model.

My workaround workflow is:

  1. Add-Migration WHATEVERNAME (Makes a blank migration)
  2. Delete this migration.
  3. Run: Update-Database
  4. Recompile & Run (Now without error)


  • The __MigrationHistory hashes of the latest migration match in both script and in the database.
  • I have my MVC application & EF project as separate projects.
  • I have tried creating an -IgnoreChanges migration, to see if applying this would mitigate the issue. It did not.

This is quite frustrating, how would I solve this issue permanently?

Note: Automatic migrations are not suitable for my scenario.

6/12/2014 11:20:39 AM

Popular Answer

Well, it's almost impossible to understand what's wrong without knowing much more detail. So all I can do is give you some clues of what you could try.

  1. Stopping and restarting the app should not cause the DB to get out of date. Is it only when debugging? Have you tried running the app without debugging? Then recycle the app pool and running the app again.

  2. Do you have any weird post-build step that will overwrite some DLL in your "bin" folder?

  3. Is your app doing something that changes the database schema, thereby invalidating it when you next start up? Run SQL profiler to check what is happening to the DB when your app starts up.

  4. Migrate back to the first version of your schema, and then back again (backup your DB first):
    update-database -TargetMigration:0 -verbose


    update-database -verbose

  5. Temporarily comment out the bulk of your app to try to isolate the cause.

  6. Create a brand new app with EF configured in the same way, copy the connection string and see if it happens for that. If not, then there must be something different. If yes, then show us your EF settings.

Hopefully something here that could give you an idea at least. Good luck!

6/12/2014 11:57:45 AM

Related Questions


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