Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django "You have unapplied migrations". Which ones?

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?

like image 418
Pier1 Sys Avatar asked Jul 04 '15 16:07

Pier1 Sys


People also ask

How do I see unapplied migrations in Django?

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? One way to do this is to look at the django_migrations table in the DB and check which ones are applied.

How do I get rid of unapplied migrations?

Yes, you can just delete them from migrations folder (dont delete the migrations folder itself).


3 Answers

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.

like image 99
Kevin Christopher Henry Avatar answered Oct 24 '22 05:10

Kevin Christopher Henry


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.

like image 26
vabada Avatar answered Oct 24 '22 06:10

vabada


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.

like image 12
countermeasure Avatar answered Oct 24 '22 06:10

countermeasure