問(wèn)題描述
我們正在使用 TFS,并且我們的 Dev 有不同的分支.
We are using TFS and have different branches for our Dev.
在分支 A 中,我們進(jìn)行了遷移以更改列大小
in the branch A we made a migration to change a column size
在分支 B 中,我們進(jìn)行了遷移以添加新表.這個(gè)分支不知道分支A的修改!!
in the branch B we made a migration to add a new table. This branch doesn not know about the branch A modification !!
兩個(gè)修改都合并到主分支.
both modification are merged to the main branch.
當(dāng)我更新數(shù)據(jù)庫(kù)時(shí),它會(huì)進(jìn)行 2 次遷移,但最后告訴我有待處理的更改.如果我執(zhí)行添加遷移,它會(huì)創(chuàng)建與第一次遷移相同的遷移(在分支 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).
無(wú)法更新數(shù)據(jù)庫(kù)以匹配當(dāng)前模型,因?yàn)橛写幚砀暮妥詣?dòng)遷移被禁用.要么寫(xiě)掛起的模型更改基于代碼的遷移或啟用自動(dòng)遷移.放DbMigrationsConfiguration.AutomaticMigrationsEnabled 為 true 以啟用自動(dòng)移民.您可以使用 Add-Migration 命令將掛起的模型更改寫(xiě)入基于代碼的遷移.
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.
是否因?yàn)槲疑洗芜w移的屬性 Target de IMigrationMetadata 的內(nèi)容中缺少某些內(nèi)容,因?yàn)樗恢赖谝淮芜w移?
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 遷移步驟包含一個(gè)元數(shù)據(jù)文件,該文件具有模型簽名,該簽名是遷移步驟的結(jié)果.合并時(shí)的問(wèn)題是在分支 B 中完成的遷移的簽名不包括在分支 A 中的遷移中完成的內(nèi)容.只要遷移在分支中,這是正確的.合并時(shí)會(huì)出錯(cuò).
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.
要解決這個(gè)問(wèn)題,您必須使用
To remedy it, you have to regenerate the meta-data of the latter migration with
add-migration MyMigrationName
在沒(méi)有 -force
參數(shù)的現(xiàn)有遷移上運(yùn)行 add-migration
將僅重新生成元數(shù)據(jù).
Running add-migration
on an existing migration without the -force
parameter will regenerate just the metadata.
我在 中寫(xiě)了一篇關(guān)于合并場(chǎng)景的深入演練EF 遷移和合并沖突 在我的博客上發(fā)布.
I wrote an in depth walk-through of a merging scenario in the EF Migrations and a Merge Conflict post on my blog.
這篇關(guān)于在不同的 TFS 分支上工作時(shí)丟失 EF 代碼優(yōu)先遷移?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!