EF Data migrations won't detect changes when adding new migration

I had a similar problem where a new migration was not being found, and so update-database was giving me the following error no matter what I did:

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.
You can use the Add-Migration command to write the pending model changes to a code-based migration.

Doing a "batch clean" solved my problem, suggesting EF was using an old/invalid assembly from a folder other than the currently selected 'solution configuration (e.g. DEBUG)'.

To do a batch clean:

  1. Select Main Menu -> Build -> Batch Build...
  2. Click Select All
  3. Click Clean

Close dialog, rebuild and re-attempt migration.

Hope this helps someone else out there.


oops. In my case I was adding a new root entity not referenced by any other entity. The result was simply that code first had no reason to generate a migration for the entity. Once I added the code into the DbContext (a dbset) it worked like a charm.


Just got the same problem but figured out that my new field was added as a member variable and not a property - it was missing the {get; set;} part and that makes migration skip that field.

May not be your case but it might help someone else.