django.db.migrations.exceptions.InconsistentMigrationHistory

后端 未结 25 1068
耶瑟儿~
耶瑟儿~ 2020-12-04 08:16

When I run python manage.py migrate on my Django project, I get the following error:

Traceback (most recent call last):
File \"manage.py\", line         


        
25条回答
  •  情深已故
    2020-12-04 09:01

    Before performing any other steps, back up your database. Then back it up again.

    Remove any custom user model code out of the way, disable your custom model and app in settings, then:

    python manage.py dumpdata auth --natural-primary --natural-foreign > auth.json
    python manage.py migrate auth zero  # This will also revert out the admin migrations
    

    Then add in your custom model, set it in settings, and re-enable the app. Make sure you have no migrations on this app yet.

    Then:

    python manage.py makemigrations 
    python manage.py migrate
    python manage.py loaddata auth.json  # Assumes your user-model isn't TOO dissimilar to the standard one.
    

    Done!

提交回复
热议问题