Skip to content

Merging migrations by manual causes incorrect migration.Designer.cs metadata #3835

Closed

Description

@kot-pilot

Entity framework core seems to be really better suited for working on migrations in team environment than previous versions were. But merging migrations which were created in different branches (like mentioned in this manual https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/teams) will cause the last created migration's .Designer.cs metadata to be not correct (as it will contain snapshot, which won't include first merged migration's changes). As I understand, migration.Designer.cs snapshot is used when we call 'dotnet ef migrations remove' to restore previous version of ContextSnapshot, but in case with merged migrations restored snapshot will be wrong.

Here is the example repository which I've created to play around, which shows the situation.
https://github.com/kot-pilot/frankenstein
Initially I've created migration with table named 'First', then created 2 branches, one created migration with 'Second' table and another created migration with 'Third' table. After merging that branches migration.Designer.cs of Third's migration missing the information about 'Second' migration (https://github.com/kot-pilot/frankenstein/blob/master/frankenstein/EntityFramework/Migrations/20220414185644_third.Designer.cs)
Now this causes that when I call 'dotnet ef migrations remove' ContextSnapshot is getting wrong state.

So the questions are:

  1. Maybe that situation should be mentioned in this manual? https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/teams
  2. Are there any further developing plans to prevent this situations to happen? Like for example don't store snapshots in migration.Designer.cs and when we call 'dotnet ef migrations remove' to try to calculate previous version of ContextSnapshot by somehow using migration's down method code and not by using migrations .Designer.cs metadata?

Activity

  1. transferred this issue fromdotnet/efcoreon Apr 25, 2022
  2. transferred this issue fromdotnet/efcoreon Apr 25, 2022
  3. added this to the 7.0.0 milestone on Apr 25, 2022
  4. jasekiw commented on Mar 16, 2023

    @jasekiw

    This a major issue for my team. We have internal documentation that instructs us to ignore the Microsoft documentation since it is incomplete. Our documentation states that when doing a merge of latest changes into your feature branch you should remove your migration(s). merge, re-add your migration. This is a slow process though and has caused a lot of additional work when merging pull requests. I have to merge a pull request, then instruct the next pull request owner to pull in the changes and regenerate their migration. Rinse and repeat. After the team grows to a considerable size, this will no longer be an option as merges have to be coordinated with a lot of involvement of each developer.

  5. removed their assignment
    on Jul 8, 2023
  6. added a commit that references this issue on Aug 11, 2026
    bb42937
  7. modified the milestones: 7.0.0, 11.0.0 on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions