3
votes

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?

1
Have you run the command 'Enable-Migrations'? and then run the 'update-database'. Or use update-database -force. If not check AutomaticMigrationsEnabled and set to AutomaticMigrationsEnabled = trueDSR
"enable-migrations" says "migrations are already enabled." "update-database -force" says "no pending explicit migrations." After that, if I run the project, I still get the error.James in Indy
Use -ConnectionProviderName and -ConnectionString with your add-migration and update-database to sure migration is using correct db, I had something like this problem in my project.Masoud

1 Answers

6
votes

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.