[英]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...".
稍后我希望添加新迁移时,Add-Migration命令会抱怨其“无法生成显式迁移,因为以下显式迁移正在等待......”。 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...".
如果我尝试解决此问题,Update-Database会指示“无法更新数据库以匹配当前模型,因为有[新]待处理的更改...”。 I don't understand why EF migrations getting out of sync since I'm only making changes to the model.
我不明白为什么EF迁移不同步,因为我只是对模型进行了更改。
For me the issue was that we had renamed the namespace of the migration 2014123456_Initial.cs. 对我来说,问题是我们已经重命名了迁移2014123456_Initial.cs的命名空间。
But VS had not regenerated the namespace in its associated 2014123456_Initial.Designer.cs. 但VS没有在其关联的2014123456_Initial.Designer.cs中重新生成名称空间。
Once the Designer.cs was changed to use the same namespace, it all started working again. 一旦Designer.cs被更改为使用相同的命名空间,它就会再次开始工作。
I was having the same issue and the solution was: 我遇到了同样的问题,解决方案是:
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 . 要添加到IamDOM解决方案,还要添加空迁移和更新数据库 。
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. 我发现VS在某种程度上感到困惑,并没有实际将迁移添加到.csproj。 Closing, re-opening VS then re-including the migration in the project and saving-all worked.
关闭,重新打开VS然后重新包括项目中的迁移和保存 - 全部工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.