django.db.migrations.exceptions.InconsistentMigrationHistory

后端 未结 25 1175
耶瑟儿~
耶瑟儿~ 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:12

    This happened to me in a new project after I added a custom User model, per the recommendation in the django docs.

    If you’re starting a new project, it’s highly recommended to set up a custom user model, even if the default User model is sufficient for you.

    Here is what I did to solve the problem.

    1. Delete the database db.sqlite3.
    2. Delete the app/migrations folder.

    Per @jackson, temporarily comment out django.contrib.admin.

    INSTALLED_APPS = [
    ...
    #‘django.contrib.admin’,
    ...
    ]
    

    Also comment out the admin site in urls.py:

    urlpatterns = [
        path('profile/', include('restapp.urls')),
        #path('admin/', admin.site.urls),
    ]
    

    If you don't comment out the path('admin/'), you will get error "LookupError: No installed app with label 'admin'" when you run

    python manage.py migrate
    

    After the migrations finish, uncomment both of the above.

提交回复
热议问题