Django "ProgrammingError: relation does not exist" in CI
Django connected to Postgres and queried a table that does not exist. The migrations that create that relation were not applied to the CI database before the query ran. This is deterministic.
What this error means
Tests, seeding, or app boot fail with "ProgrammingError: relation 'orders' does not exist". The connection works; the schema is just missing because migrate did not run first.
django.db.utils.ProgrammingError: relation "orders" does not exist
LINE 1: SELECT ... FROM "orders" ...Common causes
Migrations not applied before queries
A data load, fixture, or test queried the table before migrate created it.
Missing migration for a model
A model exists but its makemigrations output was never generated/committed, so the table is never created.
Wrong database targeted
The code points at a different database than the one migrations were applied to.
How to fix it
Apply migrations before anything queries the schema
python manage.py migrate --noinput
python manage.py loaddata fixtures.json # only after migrate
python manage.py testEnsure the model has a migration
- Run
makemigrationsfor the app and commit the result. - Confirm CI runs
migrateagainst the same database the code uses. - Order setup so migrate precedes any query or fixture load.
How to prevent it
- Always
migratebefore tests, fixtures, or seeding. - Add
makemigrations --checkso missing migrations fail fast. - This is deterministic - retrying without migrating fails identically.