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

丶灬走出姿态 提交于 2019-12-10 13:15:45

问题


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...". I.e., 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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/20110670/ef-add-migration-indicates-no-pending-explicit-migrations-but-update-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!