在不同的 TFS 分支上工作时丢失 EF 代码优先迁移?

时间:2023-03-30
本文介绍了在不同的 TFS 分支上工作时丢失 EF 代码优先迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我们正在使用 TFS,并且我们的 Dev 有不同的分支.

We are using TFS and have different branches for our Dev.

  1. 在分支 A 中,我们进行了迁移以更改列大小

  1. in the branch A we made a migration to change a column size

在分支 B 中,我们进行了迁移以添加新表.这个分支不知道分支A的修改!!

in the branch B we made a migration to add a new table. This branch doesn not know about the branch A modification !!

两个修改都合并到主分支.

both modification are merged to the main branch.

当我更新数据库时,它会进行 2 次迁移,但最后告诉我有待处理的更改.如果我执行添加迁移,它会创建与第一次迁移相同的迁移(在分支 A 中).

When I do an update database, it does the 2 migration but at the end tells me there is pending changes. If I do an Add-Migration, it creates the same as the 1st migration (in branch A).

无法更新数据库以匹配当前模型,因为有待处理更改和自动迁移被禁用.要么写挂起的模型更改基于代码的迁移或启用自动迁移.放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.

是否因为我上次迁移的属性 Target de IMigrationMetadata 的内容中缺少某些内容,因为它不知道第一次迁移?

Is it because something is missing in the content of the property Target de IMigrationMetadata of my last migration since it didn't know about the 1st one ?

是否可以在不同的 TFS 分支中处理迁移?

Is it possible to handle migrations in different TFS branches?

推荐答案

EF 迁移步骤包含一个元数据文件,该文件具有模型签名,该签名是迁移步骤的结果.合并时的问题是在分支 B 中完成的迁移的签名不包括在分支 A 中的迁移中完成的内容.只要迁移在分支中,这是正确的.合并时会出错.

An EF migration step contains a metadata file, that has a signature of the model that is the result of the migration step. The problem when merging is that the signature of the migration done in branch B doesn't include the stuff done in the migration in branch A. As long as the migrations are in the branches, this is correct. When merging it becomes wrong.

要解决这个问题,您必须使用

To remedy it, you have to regenerate the meta-data of the latter migration with

add-migration MyMigrationName

在没有 -force 参数的现有迁移上运行 add-migration 将仅重新生成元数据.

Running add-migration on an existing migration without the -force parameter will regenerate just the metadata.

我在 中写了一篇关于合并场景的深入演练EF 迁移和合并冲突 在我的博客上发布.

I wrote an in depth walk-through of a merging scenario in the EF Migrations and a Merge Conflict post on my blog.

这篇关于在不同的 TFS 分支上工作时丢失 EF 代码优先迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 Coldfusion 中加密并在 C# 中解密 下一篇:将 Coldfusion 加密代码转换为 C#

相关文章