Search code examples
djangodjango-southmigrate

django schemamigration creates the same migration change


I messed up merging schema migrations from multiple git branches.

Basically, all the changes are applied to DB, but when I do

python manage.py schemamigration my_app --auto 

It recreates migration file for all the changes which were recently applied.

How can I fix this?

(I tried to be smart while combining branches and run --delete-ghost-migrations and replay them.. without understanding what I was doing fully) :(


Solution

  • Here's what I think happened.

    I have a branch which I branched off from upstream/master.
    This doesn't have database schema changes I have in my local git repo.
    I worked on this branch and merged to my local branch.

    Now the migration files from the merged-in branch don't have latest schema changes in the migrations files. (Yes that's what it think is current status of DB, and compare it to my models.py files. This was the key to solve the problem.)

    Below is simplified view of what happened.

    003 -- change made in local branch
    004 -- change made in branch(from upstream/master) and doesn't have changes introduced in 003

    When I run schemamigration it creates

    005 -- reapplies the changes in 003

    and run migrate, and fails.

    I fixed the problem by modifying the contents of migrations files manually.