問題描述
我們正在使用 TFS,并且我們的 Dev 有不同的分支.
We are using TFS and have different branches for our Dev.
在分支 A 中,我們進行了遷移以更改列大小
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 代碼優先遷移?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!