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
The order of INSTALLED_APPS
seems important.
If you always put your recent works on top/beginning of the list they'll always be loaded properly in regard to django.contrib.admin. Moving my works to the beginning of the INSTALLED_APPS
list fixed this problem for me.
The reason Kun Shi's solution may have worked maybe it ran the migrations in a different order.
when you create a new Django project and run
python manage.py migrate
The Django will create 10 tables for you by default including one auth_user table and two start with auth_user.
when you want to create a custom user model inherit from AbstractUser, you will encounter this problem with error message as follow:
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency account.0001_initial on database 'default'.
I solve this problem by dropping my entire database, and create a new one. And this replaced the three tables I mentioned.
If you set AUTH_USER_MODEL in settings.py like this:
AUTH_USER_MODEL = 'custom_user_app_name.User'
you should comment this line before run makemigration and migrate commands. Then you can uncomment this line again.
Here how to solve this properly.
Follow these steps in your migrations folder inside the project:
Voila.
just delete the sqlite file or run flush the databse 'python manage.py flush' and then run makemigrations and migrate commands respectively.
If you are working on an empty database a quick fix could be running the migrations for the account app, before any other app migrations.
$ ./manage.py migrate account
And then:
$ ./manage.py migrate