简体   繁体   中英

EF6 Code Migrations - Database is different, yet the same

Sorry to post such a general question, but this could have multiple answers for multiple situations (and I may have to recreate the db before I can get an answer), so here goes:

We have a C# project using EF6 which has been utilizing EF Migrations successfully for months. This morning, when I try to run my project, I get this this all-too-familiar error:

System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException' occurred in EntityFramework.dll but was not handled in user code

Additional information: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.

Except that I can find no evidence of anything having changed.

  • The database's __MigrationHistory table matches the Migrations in the project.
  • If I do a "add-migration", it comes up with empty Up & Down methods.
  • We restored a database from a few nights ago (when we know it worked) to a temp DB and did a compare, and no structural changes were found.
  • I even tried running "update-database" on the empty migration, which worked, but the error still occurs.

Any ideas on how this scenario can occur?

We found the problem. The Core project in our solution was upgraded from EF 6.0.2 to EF 6.1.1, but the MVC project was not.

This did not cause a problem when it was initially done days ago. But yesterday, a team member created the first migration with the new version (just added data, no structural changes). Once that migration ran, the MVC project could no longer interact with the db.

What finally tipped us off was seeing a newer ProductVersion in the __MigrationHistory table.

Once I upgraded the MVC project, the problem was resolved.

Thanks to those of you who offered suggestions. Hopefully, if someone else has the same symptom, they can find an answer among these posts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM