How to manage Migrations in a project with multiple branches?

前端 未结 7 594
情书的邮戳
情书的邮戳 2020-12-12 11:39

I have an ASP.NET MVC3 project that uses Entity Framework 4.3 with the code-first approach. I use Migrations to keep the database up-to-date.

The project is under so

相关标签:
7条回答
  • 2020-12-12 12:17

    Rowan Miller has made a great video about this topic on channel 9: Migrations - Team Environments. It refers to entity framework 6.

    It describes a scenario where first developer A and B are working on the same model and A checks in first. Now developer B has to deal with the problems he has when he gets the latest version from A.

    This is essentially the same like having conflicts between different branches, because the general problem is merging migration changes done it the same time but effectively having a different source state of the model.

    The solution is:

    • When resolving the conflicts of the version control system, developer B has to accept both changes from himself and developer A.
    • An UpdateDatabase command of developer B would still fail at this time (Error message: "Unable to update database to match the current model because there are pending changes...")
    • Developer B has to create an "empty migration" using the IgnoreChanges option:

    Add-Migration NameOfMigration -IgnoreChanges

    Then the UpdateDatabase command will succeed.


    Source of the problem

    The source of the error occurring when updating the database is because EF stores a snapshot of the model a migration refers to in the resx file within the migration file.

    In this case developers B snapshot of the "current model" is not correct after getting / merging the changes made by developer A.

    0 讨论(0)
提交回复
热议问题