Lose EF Code First Migration when working on different TFS branches?

风流意气都作罢 提交于 2019-11-29 20:18:05

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

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

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

As an addition to Anders Abel's answer and for those of you who are having the issue when trying to regenerate the last migrations metadata causing EF to create a separate migration with a 1 appended to it.

You must include the full date/time stamp.

E.g.

If the filename of your previous migration is 201701011322_MakeChangesToPotatoTable

Then you must include the fullname properly in the "Add-Migration" command.

I.E.

Add-Migration 201701011322_MakeChangesToPotatoTable
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!