简体   繁体   English

Update-Database Add-Migration循环

[英]The Update-Database Add-Migration loop

I thought I figured it out when I disabled AutomaticMigrations. 我以为我在禁用AutomaticMigrations时知道了。

I Update-Database then Add new column name to DAL class. 我更新数据库,然后将新的列名称添加到DAL类。

Then execute Add-Migration 然后执行添加迁移

But I am caught in a loop of nonsense. 但是我陷入了胡说八道。

I execute Update-Database and am treated to ... Applying explicit migrations: [a list of the current migrations]. 我执行Update-Database,并被视为……应用显式迁移:[当前迁移的列表]。

then this line for each migration. 然后此行用于每次迁移。 Applying explicit migration: [id] 应用显式迁移:[id]

Then it warning me that the model is NOT up to date. 然后它警告我该模型不是最新的。 So I execute Add-Migration and get the error... Unable to generate an explicit migration because the following explicit migrations are pending: [the same list I just saw applied] 因此,我执行Add-Migration并收到错误...无法生成显式迁移,因为以下显式迁移正在处理中:[与我刚刚看到的相同列表相同]

WTF? WTF?

I resolved this through the following steps. 我通过以下步骤解决了这个问题。

  1. Delete the dataabase file your DAL project is updating. 删除您的DAL项目正在更新的数据库文件。
  2. Remove the offending migration. 删除有问题的迁移。 // Comment out the offending column or table. //注释掉有问题的列或表。
  3. Execute Update-Database. 执行更新数据库。
  4. Uncomment changes. 取消注释更改。
  5. Add-Migration 添加迁移
  6. Update-Database 更新数据库
  7. Runtime check. 运行时检查。
  8. Check-in 报到

Good luck if you run into this problem. 如果遇到这个问题,祝您好运。

I further ran into problems when I added code that explicitly called the initializer to speed up startup time. 当我添加显式调用初始化程序以加快启动时间的代码时,我进一步遇到了问题。 Then whenever I did an update-database...it would use my context class, try to do the initializer and fail. 然后,每当我执行更新数据库...时,它将使用我的上下文类,尝试执行初始化程序并失败。

Code-First is a good step in the right direction but it has all these be careful scenarios. 代码优先是朝正确方向迈出的良好一步,但它具有所有这些谨慎的方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架代码优先:迁移失败,更新数据库,强制不必要的(?)添加迁移 - Entity Framework code-first: migration fails with update-database, forces unneccessary(?) add-migration 在存在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 EF Add-Migration表示“没有待定的显式迁移”,但Update-Database会抱怨“..有待处理的更改” - EF Add-Migration indicates “No pending explicit migrations” but Update-Database complains “..there are pending changes” 实体框架:添加迁移失败,无法更新数据库 - Entity Framework: Add-Migration fails with Unable to update database 添加迁移异常 - Add-migration Exeception "添加迁移错误" - Errors on Add-Migration 实体框架迁移更新数据库成功,但未添加数据库列 - Entity Framework Migration update-database succeeded but database column is not added “更新数据库”命令不会更新到最新版本的迁移 - "Update-Database" command does not update to the latest version of Migration 实体框架要求在已附加迁移的情况下更新数据库 - Entity Framework asks to update-database when migration is already appended
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM