python manage.py migrate finishes but the tables for my app are missing
(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.
Fix it fast
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 showmigrations2Match what you see, then jump to its fix
- 1
showmigrations prints (no migrations) next to the app nameThe app has no migrations yetFix - 2
The 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
showmigrations shows [X] but the table does not exist; someone ran migrate --fakeThe migrations were marked as applied without runningFix
- 1
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 myapp2Fix
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 migrate3Verify
The tables exist and showmigrations shows [X] on the new migration.
python manage.py showmigrations myappConfirmed by docs.djangoproject.com
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=default3Verify
Open the same database that settings name and list its tables.
python manage.py dbshellConfirmed by docs.djangoproject.com
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 00012Fix
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 myapp3Verify
The tables now exist.
python manage.py showmigrations myappConfirmed by docs.djangoproject.com
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:
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Django cannot load MySQLdb and asks whether mysqlclient is installed
Error loading MySQLdb module: Did you install mysqlclient or MySQL-python?
Django's MySQL backend imports MySQLdb, which is provided by the mysqlclient package.
3 causes, each with a fixDatabases
Django save fails on PostgreSQL: null value in a column violates a not-null constraint
django.db.utils.IntegrityError: null value in column "price" of relation "shop_product" violates not-null constraint
A model field is NOT NULL in the database unless it has null=True.
3 causes, each with a fixDatabases
Django migration on PostgreSQL stops with 'pending trigger events'
django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events
PostgreSQL runs a Django migration in one transaction.
2 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Spring Boot fails on startup: HikariPool-1 exception during pool initialization
Caused by: ... (the underlying driver exception)
HikariCP opens one connection when the pool starts, and the startup fails when that connection fails.
3 causes, each with a fix