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

后端 未结 16 1894
情话喂你
情话喂你 2020-12-09 14:53

I am using Entity Framework 5.0 Data migrations along with code first. When i add a new field to my model and execute the following command in the package manager console.

16条回答
  •  失恋的感觉
    2020-12-09 15:10

    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.

提交回复
热议问题