Conflicting migrations detected;

Hi,
Let me hope this does not have a negative effect on the database.
This happened on server upgrade from v19 to v20. It show this error when you migrate the database:-

python manage.py migrate
CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0041_a uto_20210816_1057, 0040_auto_20210726_2000 in oppia; 0010_auto_20210816_1057, 0010_auto_20210726_2 000 in summary; 0005_auto_20210726_2000, 0005_auto_20210716_1644 in reports).
To fix them run ‘python manage.py makemigrations --merge’

When you run the python manage.py makemigrations --merge, and then migrate, it works fine.

Hi,
Django throws that error if there is more than one “end migration”, or leaf node in the migrations dependency tree. I guess in your case the dependency tree would look something like this:

                       0039_auto_20210627_1445
                        /                  \
                       /                    \
      0040_auto_20210726_2000         0040_auto_20210716_1644
                                                 |
                                                 |
                                      0041_auto_20210816_1057

That the issue comes from the fact that in that project there were model changes that created additional migrations that diverge from the core codebase (for example, the 0040_auto_20210726_2000 migration doesn’t appear in the core app). Then, when you pulled the changes that include the new migrations, there are two leaf nodes and Django doesn’t know which one should apply first.

So there’s two posible methods to solve this problem:

  • Modify one of the migrations and add as a dependency the other leaf node so there is only one path (modifying the dependencies attribute inside the Migration class

  • Use makemigrations --merge to let Django handle it for you, like you already did. It should have created an additional migration file, you can check it and see if everything there makes sense. If not, you can revert to the point previous to the conflict using python manage.py migrate oppia [migration_name] and use the first method.

If you didn’t find any issue, likely the --merge command worked correctly, but it would be good to double check in that migration file.
Cheers!

1 Like