陷入EF迁移边缘 [英] stuck in EF migration limbo

查看:68
本文介绍了陷入EF迁移边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以某种方式使我的EF5项目进入无法进行的状态。

i have somehow gotten my EF5 project into a state where I can't proceed.

当我执行更新数据库时,我得到:

When I do an 'update-database' i get:


由于存在未决的更改并且自动迁移被禁用,因此无法更新数据库以匹配当前模型。将挂起的模型更改写到基于代码的迁移中,或者启用自动迁移。将DbMigrationsConfiguration.AutomaticMigrationsEnabled设置为true以启用自动迁移。
您可以使用Add-Migration命令将待处理的模型更改写入基于代码的迁移中。

Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration. You can use the Add-Migration command to write the pending model changes to a code-based migration.

好,很好,所以我尝试进行 add-migration,然后得到:

ok, fine, so i try to 'add-migration', and i get:


由于以下显式迁移是无法生成显式迁移的待处理:[]。在尝试生成新的显式迁移之前,请先应用待处理的显式迁移。

Unable to generate an explicit migration because the following explicit migrations are pending: [ ]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

20 GOTO 10 ??

20 GOTO 10 ??

我现在应该做什么? (除了切换到NHibernate吗?)

what am i supposed to do at this point? (beyond switching to NHibernate?)

推荐答案

对我有用的是:


  1. 将所有更改(首先进行备份)恢复为已知的良好状态。

  2. 执行 add-migration DummyMigration 。这产生了一些虚假的更改,我对此进行了评论

  3. 称为 update-database ,将迁移+元数据添加到 [__MigrationHistory] ​​表。

  4. 进行所需的更改(来自我之前备份的代码)。

  5. 执行正常的添加迁移 / 更新数据库

  1. Reverting all my changes (making a backup first) back to a known good state.
  2. Doing add-migration DummyMigration. That produced some spurious changes that I commented
  3. Called update-database to add the migration + metadata to the [__MigrationHistory] table.
  4. Make the changes I needed (from the backup of the code I took earlier).
  5. Do the normal add-migration/update-database.

不太理想,很高兴看看是否有更好的解决方案,但这对我有用。

Not ideal, and would be cool to see if there's a better solution, but that worked for me.

这篇关于陷入EF迁移边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆