插入迁移
Insert a migration
故事是这样的。我们在使用 Entity Framework Code First 迁移的源代码控制中有一个产品。为了这个问题,有两个分支,开发和生产。目前开发分支有几个不在生产分支的迁移,但它们是从生产分支的最后一个迁移开始的。
现在,我们需要对生产分支进行一个小的架构更改。我们通过添加迁移来做到这一点。然后将其发布到生产站点。
那么,我们如何将这些变更集成到开发分支中呢?开发分支中的迁移必然是生产站点上的迁移的后代,但我们只是在生产站点上插入了一个新的迁移。这意味着当我们合并到开发分支时,迁移失败,因为存在乱序迁移。
那么,在我的开发分支中,是否有任何方法可以从另一个分支插入迁移,从而将现有的迁移分流到列表中?
我在合并来自不同开发人员的更改时处理过这个问题。在为这个答案做一些研究时,我遇到了 this handy article 这可能比我能更好地解释它。 las,你被我困住了。有几点需要注意:
Entity Framework 不会每次都直接将数据库与您的 类 进行比较。相反,它比较它生成的 edmx
模型。
因此,您在尝试更新时会收到警告
Unable to update database to match the current model because there are pending changes and automatic migration is disabled…
尽管它将实际执行更新。该错误是指它比较的快照(?)edmx
。
最简单的方法是添加一个空白'merge migration'。以下是文章中的步骤:
Ensure any pending model changes in your local code base have been written to a migration. This step ensures you don’t miss any
legitimate changes when it comes time to generate the blank migration.
Sync with source control.
Run Update-Database to apply any new migrations that other developers have checked in.
Note:if you don’t get any warnings from the Update-Database command
then there were no new migrations from other developers and there is
no need to perform any further merging.
Run Add-Migration [pick_a_name] –IgnoreChanges (e.g. Add-Migration Merge –IgnoreChanges). This generates a migration with all the
metadata (including a snapshot of the current model) but will ignore
any changes it detects when comparing the current model to the
snapshot in the last migrations (meaning you get a blank Up and Down
method).
故事是这样的。我们在使用 Entity Framework Code First 迁移的源代码控制中有一个产品。为了这个问题,有两个分支,开发和生产。目前开发分支有几个不在生产分支的迁移,但它们是从生产分支的最后一个迁移开始的。
现在,我们需要对生产分支进行一个小的架构更改。我们通过添加迁移来做到这一点。然后将其发布到生产站点。
那么,我们如何将这些变更集成到开发分支中呢?开发分支中的迁移必然是生产站点上的迁移的后代,但我们只是在生产站点上插入了一个新的迁移。这意味着当我们合并到开发分支时,迁移失败,因为存在乱序迁移。
那么,在我的开发分支中,是否有任何方法可以从另一个分支插入迁移,从而将现有的迁移分流到列表中?
我在合并来自不同开发人员的更改时处理过这个问题。在为这个答案做一些研究时,我遇到了 this handy article 这可能比我能更好地解释它。 las,你被我困住了。有几点需要注意:
Entity Framework 不会每次都直接将数据库与您的 类 进行比较。相反,它比较它生成的
edmx
模型。因此,您在尝试更新时会收到警告
Unable to update database to match the current model because there are pending changes and automatic migration is disabled…
尽管它将实际执行更新。该错误是指它比较的快照(?)edmx
。
最简单的方法是添加一个空白'merge migration'。以下是文章中的步骤:
Ensure any pending model changes in your local code base have been written to a migration. This step ensures you don’t miss any legitimate changes when it comes time to generate the blank migration.
Sync with source control.
Run Update-Database to apply any new migrations that other developers have checked in.
Note:if you don’t get any warnings from the Update-Database command then there were no new migrations from other developers and there is no need to perform any further merging.
Run Add-Migration [pick_a_name] –IgnoreChanges (e.g. Add-Migration Merge –IgnoreChanges). This generates a migration with all the metadata (including a snapshot of the current model) but will ignore any changes it detects when comparing the current model to the snapshot in the last migrations (meaning you get a blank Up and Down method).