When working on various TFS branches, do you lose EF Code First Migration?

.net coldfusion ef-code-first ef-migrations entity-framework

Question

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

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

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

  3. both modification are merged to the main branch.

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).

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.

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 ?

Is it possible to handle migrations in different TFS branches?

1
31
4/16/2012 9:46:27 AM

Accepted Answer

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.

34
5/1/2012 6:50:40 AM

Popular Answer

With EF core, the current state of the model is kept in ***ModelSnapshot.cs. It is normally merged so you don't have anything to do... unless there is a conflict.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow