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

前端 未结 3 1333
攒了一身酷
攒了一身酷 2020-12-23 09:44

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 mad

相关标签:
3条回答
  • 2020-12-23 10:38

    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.

    0 讨论(0)
  • 2020-12-23 10:40

    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.

    0 讨论(0)
  • 2020-12-23 10:47

    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
    
    0 讨论(0)
提交回复
热议问题