Your django_migrations table in your database is the cause of inconsistency and deleting all the migrations just from local path won't work.

You have to truncate the django_migrations table from your database and then try applying the migrations again. It should work but if it does not then run makemigrations again and then migrate.

Note: don't forget to take a backup of your data.

Since you are using a custom User model, your can first comment out


in your Installed_Apps settings. Then run

python migrate.

When done uncomment


Lets start off by addressing the issue with most of the answers on this page:

You never have to drop your database if you are using Django's migration system correctly and you should never delete migrations once they are comitted

Now the best solution for you depends on a number of factors which include how experienced you are with Django, what level of understanding you have of the migration system, and how valuable the data in your database is.

In short there are two ways you can address any migration error.

  1. Take the nuclear option. Warning: this is only an option is you are working alone. If other people depend on existing migrations you cannot just delete them.

    • Delete all of your migrations, and rebuild a fresh set with python3 -m manage makemigrations. This should remove any problems you had with dependencies or inconsistencies in your migrations.
    • Drop your entire database. This will remove any problems you had with inconsistencies you had between your actual database schema and the schema you should have based on your migration history, and will remove any problems you had with inconsistencies between your migration history and your previous migration files [this is what the InconsistentMigrationHistory is complaining about].
    • Recreate your database schema with python3 -m manage migrate
  2. Determine the cause of the error and resolve it, because (speaking from experience) the cause is almost certainly something silly you did. (Generally as a result of not understanding how to use the migration system correctly). Based on the error's I've caused there are three categories.

    1. Inconsistencies with migration files. This is a pretty common one when multiple people are working on a project. Hopefully your changes do not conflict and makemigrations --merge can solve this one, otherwise someone is going to have to roll back their migrations to the branching point in order to resolve this.
    2. Inconsistencies between your schema and your migration history. To manage this someone will have either edited the database schema manually, or deleted migrations. If they deleted a migration, then revert their changes and yell at them; you should never delete migrations if others depend on them. If they edited the database schema manually, revert their changes and then yell at them; Django is managing the database schema, no one else.
    3. Inconsistencies between your migration history and your migrations files. [This is the InconsistentMigrationHistory issue the asker suffers from, and the one I suffered from when I arrived at this page]. To manage this someone has either manually messed with the django_migrations table or deleted a migration after it was applied. To resolve this you are going to have to work out how the inconsistency came about and manually resolve it. If your database schema is correct, and it is just your migration history that is wrong you can manually edit the django_migrations table to resolve this. If your database schema is wrong then you will also have to manually edit that to bring it in line with what it should be.

Based on your description of the problem and the answer you selected I'm going to assume you are working alone, are new to Django, and don't care about your data. So the nuclear option may be right for you.

If you are not in this situation and the above text looks like gibberish, then I suggest asking the Django User's Mailing List for help. There are very helpful people there who can help walk you through resolving the specific mess you are in.

Have faith, you can resolve this error without going nuclear!

Here how to solve this properly.

Follow these steps in your migrations folder inside the project:

  1. Delete the _pycache_ and the 0001_initial files.
  2. Delete the db.sqlite3 from the root directory (be careful all your data will go away).
  3. on the terminal run:
      python makemigrations
      python migrate


kun shi


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.


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

Python makemigrations appname

Python migrate appname

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

$: Python makemigrations appname

$: Python migrate appname

when you create a new Django project and run

python 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 are working on an empty database a quick fix could be running the migrations for the account app, before any other app migrations.

$ ./ migrate account

And then:

$ ./ migrate

If you set AUTH_USER_MODEL in 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.

just delete the sqlite file or run flush the databse 'python flush' and then run makemigrations and migrate commands respectively.


when you create a new project and with no apps, you run the

python migrate

the Django will create 10 tables by default.

If you want create a customer user model which inherit from AbstractUser after that, you will encounter this problem as follow message:

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

finally, I drop my entire databases and run

I encountered this when migrating from Wagtail 2.0 to 2.4, but have seen it a few other times when a third party app squashes a migration after your current version but before the version you’re migrating to.

The shockingly simple solution in this case at least is:

./ migrate
./ makemigrations
./ migrate

i.e. run a single migrate before trying to makemigrations.

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.


Also comment out the admin site in

urlpatterns = [
    path('profile/', include('restapp.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 migrate

After the migrations finish, uncomment both of the above.

First delete all the migrations and db.sqlite3 files and follow these steps:

$ ./ makemigrations myapp 
$ ./ squashmigrations myapp 0001(may be differ)

Delete the old migration file and finally.

$ ./ migrate

If that exception was reveal itself while you are trying to create your own User model instead of standard follow that instruction
I have found my problem resolve by follow that instruction step by step:

  1. Create a custom user model identical to auth.User, call it User (so many-to-many tables keep the same name) and set db_table='auth_user' (so it uses the same table)
  2. Throw away all your migrations
  3. Recreate a fresh set of migrations
  4. Sacrifice a chicken, perhaps two if you're anxious; also make a backup of your database
  5. Truncate the django_migrations table
  6. Fake-apply the new set of migrations
  7. Unset db_table, make other changes to the custom model, generate migrations, apply them

It is highly recommended to do this on a database that enforces foreign key constraints. Don't try this on SQLite on your laptop and expect it to work on Postgres on the servers!

There is another reason besides user error that can lead to this sort of problem: a known issue with Django when it comes to squashed migrations.

We have a series of migrations that work perfectly fine in Python 2.7 + Django 1.11. Running makemigrations or migrate always works as it should, etc., even (for the purpose of testing) when the database is freshly re-created.

However, as we move a project to Python 3.6 (currently using the same Django 1.11) I've been stuck trying to figure out why the same migrations apply just fine only the first time they are run. After that, any attempt to run makemigrations or even just migrate results in the error:


wherein migration foo.0040-thing is applied before its dependency foo.0038-something-squashed-0039-somethingelse (we only happen to have that one squashed migration... the rest are much more straightforward).

What's bugged me for a while is why this only happens on Python 3. If the DB is truly inconsistent this should be happening all the time. That the migrations appear to work perfectly fine the first time they are applied was equally confounding.

After much searching (including the present Q&A thread), I stumbled upon the aforementioned Django bug report. Our squash migration did indeed use the b prefix in the replaces line (e.g., replaces = [(b'', 'foo.0038-defunct'),.......]

Once I removed the b prefixes from the replaces line it all worked normally.

Your Error is essentially:

Migration "B" is applied before its dependency "A" on database 'default'.

Sanity Check: First, open your database and look at the records in the 'django_migrations' table. Records should be listed in Chronological order (ex: A,B,C,D...).

Make sure that the name of the "A" Migration listed in the error matches the name of the "A" migration listed in the database. (They can differ if you had previously, manually, edited or deleted or renamed migration files)

To Fix This, rename migration A. either in the database or rename the filename. BUT make sure the changes matches up with what other developers on your team have in their databases (or the changes matches what on your production database)

This Problem will come most of the time if you extend the User Model post initial migration. Because whenever you extend the Abstract user it will create basic fields which were present un the model like email, first_name, etc.

Even this is applicable to any abstract model in django.

So a very simple solution for this is either create a new database then apply migrations or delete [You all data will be deleted in this case.] the same database and reapply migrations.