django.db.migrations.exceptions.InconsistentMigrationHistory

后端 未结 25 1172
耶瑟儿~
耶瑟儿~ 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 08:57

    Problem

    django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency account.0001_initial on database 'default'.

    So we can migrate database without admin(admin.0001_initial) firstly.

    After its dependency migrated, execute commands to migrate admin.0001_initial.

    Solution

    1. remove 'django.contrib.admin' from INSTALLED_APPS in settings.py.
    2. execute commands:

    Python manage.py makemigrations appname

    Python manage.py migrate appname

    1. add 'django.contrib.admin' to INSTALLED_APPS in settings.py file.
    2. execute commands again:

    Python manage.py makemigrations appname

    Python manage.py migrate appname

提交回复
热议问题