简体   繁体   中英

EF Add-Migration indicates “No pending explicit migrations” but Update-Database complains “..there are pending changes”

I frequently encounter the following situation with Entity Framework code first migrations. I add some migrations and update the database with them successfully. When later I wish to add a new migration, the Add-Migration command complains that its "Unable to generate an explicit migration because the following explicit migrations are pending...". Ie, it seems to forget that its already applied those migrations previously and therefore they shouldn't be now considered as pending. If I try to workaround this issue, Update-Database indicates "Unable to update database to match the current model because there are [new] pending changes...". I don't understand why EF migrations getting out of sync since I'm only making changes to the model.

For me the issue was that we had renamed the namespace of the migration 2014123456_Initial.cs.
But VS had not regenerated the namespace in its associated 2014123456_Initial.Designer.cs.

Once the Designer.cs was changed to use the same namespace, it all started working again.

I was having the same issue and the solution was:

  1. Clean solution;
  2. Build the project which has migrations enabled (just to make sure);
  3. Build the Solution again;

This is pretty much equivalent of using the Rebuild Solution option in the Build menu.

I had the exact same problem and could not resolve it.

To add to IamDOM solution ALSO add an empty migration and update database .

For example:

Add-Migration Test

Update-Database

It worked for me few times now.

I found that VS had got confused somehow and not actually added the migrations to the .csproj. Closing, re-opening VS then re-including the migration in the project and saving-all worked.

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