Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

python manage.py migrate finishes but the tables for my app are missing

Error(no migrations)

Short answer

migrate only applies migration files that exist. If your app has no migrations package, migrate skips its models. Run makemigrations with the app label first. Also check that you migrate the database you are looking at, and that the migrations were not marked applied with --fake. showmigrations shows which case it is.

  • Applies to Django 5.2, PostgreSQL 16, MySQL 8, Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the migrations Django knows about and whether each one is applied. An app with no migrations says so; applied ones carry an [X].

    python manage.py showmigrations
  2. 2Match what you see, then jump to its fix

    1. 1showmigrations prints (no migrations) next to the app nameThe app has no migrations yetFix
    2. 2The migrations show as applied, but the table is missing in the database you openedmigrate ran against a different database than the one you inspectFix
    3. 3showmigrations shows [X] but the table does not exist; someone ran migrate --fakeThe migrations were marked as applied without runningFix

What does the error look like?

  • (no migrations)
  • relation "myapp_book" does not exist

Cause 1 of 3

The app has no migrations yet

1Check

Look for a migrations directory inside the app, with an initial migration in it.

ls myapp/migrations/
python manage.py showmigrations myapp

2Fix

Create the migrations for that app by naming it. For an app without a migrations directory, passing the app label creates one. Then migrate.

python manage.py makemigrations myapp
python manage.py migrate

3Verify

The tables exist and showmigrations shows [X] on the new migration.

python manage.py showmigrations myapp

Confirmed by docs.djangoproject.com

Did this fix it?

Cause 2 of 3

migrate ran against a different database than the one you inspect

1Check

migrate targets the default database unless you pass --database. Print which database settings the project uses.

python manage.py shell -c "from django.conf import settings; print(settings.DATABASES['default']['NAME'], settings.DATABASES['default'].get('HOST'))"

2Fix

Migrate the alias you intend to use, and check that your settings point at the database you inspect.

python manage.py migrate --database=default

3Verify

Open the same database that settings name and list its tables.

python manage.py dbshell

Confirmed by docs.djangoproject.com

Did this fix it?

Cause 3 of 3

The migrations were marked as applied without running

1Check

--fake records migrations as applied without running their SQL. The Django documentation warns this can leave the migration state needing manual recovery.

python manage.py showmigrations myapp
python manage.py sqlmigrate myapp 0001

2Fix

Unapply the migrations in the state table without touching data using --fake backwards, then apply them for real. Do this only on a database where the tables are truly missing.

python manage.py migrate myapp zero --fake
python manage.py migrate myapp

3Verify

The tables now exist.

python manage.py showmigrations myapp

Confirmed by docs.djangoproject.com

Did this fix it?

How do I stop it coming back?

  • Commit each app's migrations folder to version control so every environment runs the same files.
  • Run python manage.py makemigrations --check in CI to catch model changes that have no migration.
  • Avoid --fake except for the documented fake-initial case of adopting an existing schema.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.