简体   繁体   English

EF Add-Migration表示“没有待定的显式迁移”,但Update-Database会抱怨“..有待处理的更改”

[英]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: 我遇到了同样的问题,解决方案是:

  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 . 要添加到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.

相关问题 在显式迁移挂起时添加迁移 - Add-Migration while there are explicit migrations pending EF6 + SQL Server CE +两个上下文+从代码进行CodeFirst迁移-在添加迁移后检测未决更改 - EF6 + SQL Server CE + two contexts+ CodeFirst Migrations from code - Detect Pending Changes after Add-Migration Update-Database Add-Migration循环 - The Update-Database Add-Migration loop 无法生成显式迁移(EF5)(迁移待处理) - Unable to generate explicit migration (EF5) (migrations pending) EF迁移没有待处理的更改,但仍然抱怨有待更改。 EF如何跟踪这一点? - There are no pending changes for EF migration and still it complains that there are pending changes. How does EF keep track of this? 如何在使用基于代码的迁移时停止添加迁移检查我的数据库没有挂起的迁移? - How can I stop Add-Migration checking my database has no pending migrations when using Code-Based migrations? 实体框架代码优先:迁移失败,更新数据库,强制不必要的(?)添加迁移 - Entity Framework code-first: migration fails with update-database, forces unneccessary(?) add-migration 无法生成显式迁移,因为以下显式迁移待处理 - Unable to generate an explicit migration because the following explicit migrations are pending 在存在Cache.insert的地方进行添加迁移或更新数据库失败 - Add-migration or update-database fails where Cache.insert exists 未找到添加迁移和更新数据库命令 Visual Studio 2015 - Add-Migration and Update-Database commands not found Visual Studio 2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM