Django "You have unapplied migrations". Which ones?

DjangoDjango Migrations

Django Problem Overview


Django runserver complains:

You have unapplied migrations; 
your app may not work properly until they are applied. 
Run 'python manage.py migrate' to apply them.

How can I find out which migrations are unapplied without running migrate?

Django Solutions


Solution 1 - Django

If you're on 1.7, use python manage.py migrate --list. (docs)

If you're on 1.8 or above, use python manage.py showmigrations --list. (docs)

In either case, there will be an [X] to show which migrations have been applied.

Solution 2 - Django

A minor modification on Kevin's answer using grep, to only show unapplied migrations:

Django 1.7:

python manage.py migrate --list | grep -v '\[X\]'

Django 1.8 and above:

python manage.py showmigrations --list | grep -v '\[X\]'

Edited after ngoue's comment. Nice catch. Thanks for pointing it out.

Solution 3 - Django

You can see a list of just the unapplied migrations with the --plan option of the migrate command:

python manage.py migrate --plan

It was introduced in Django 2.2 and is documented here.

Solution 4 - Django

after using this command :

python manage.py migrate

you get the same error: You have un-applied migrations;

simple way to solve this error is to go to your project directory search for your database directory that is created after command

python manage.py migrate

in my case db created was db.sqlite3 just delete that file and go to your terminal and use manage.py makemigrations followed by manage.py migrate .

this worked for me . All the best

Solution 5 - Django

Once you run the migration command (python manage.py migrate) its always generates an auto_migration.py file in that specific app.

Also the same file you will be able to see it in your database. If that file is missing in your DB then your project will complain about "un-applied migrations".

So just go to your db and manually create an entry for auto_migration.py.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPier1 SysView Question on Stackoverflow
Solution 1 - DjangoKevin Christopher HenryView Answer on Stackoverflow
Solution 2 - DjangovabadaView Answer on Stackoverflow
Solution 3 - DjangocountermeasureView Answer on Stackoverflow
Solution 4 - DjangoGautam KumarView Answer on Stackoverflow
Solution 5 - DjangoTanviView Answer on Stackoverflow