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

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