56

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?

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
Pier1 Sys
  • 1,250
  • 2
  • 12
  • 21
  • One way to do this is to look at the django_migrations table in the DB and check which ones are applied. But I wasn't sure if there was a simpler way. – Pier1 Sys Jul 04 '15 at 16:18

5 Answers5

94

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.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
24

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.

vabada
  • 1,738
  • 4
  • 29
  • 37
  • 4
    Nope, because the `-v` option tells the `grep` command to show the lines that do not contain `[x]` – vabada May 12 '16 at 08:33
  • Should actually be `grep -v '\[X\]'` otherwise it will exclude any migrations that have an "X" in the name. – ngoue Jun 22 '18 at 16:51
  • You are indeed right ngoue. Thanks for the point. I did a quick check and a migration with an X in the name would be ignored, which is certainly not desirable. However, I guess that this rarely happens, since autogenerated migrations have lowercase names by default, for instance. Thanks for the catch! – vabada Jun 24 '18 at 08:15
  • 4
    with `grep -v '\[X\]` you'll also get application names. Use `... | grep "\[\ \]"` to show _only_ unapplied migration – Ivan Miljkovic Sep 25 '18 at 08:13
14

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.

countermeasure
  • 442
  • 4
  • 10
2

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

Gautam Kumar
  • 1,385
  • 14
  • 17
1

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.

sentence
  • 8,213
  • 4
  • 31
  • 40
Tanvi
  • 11
  • 1