Django "ProgrammingError: relation ... does not exist" (migrate before tests) in CI
Django asked Postgres for a table that has no schema. The database exists and connects, but migrations never ran against it, so the table (relation) is absent. In CI this is a missing migrate step or a test setup that skips it.
What this error means
A query fails with "django.db.utils.ProgrammingError: relation \"app_thing\" does not exist", often during a data migration, a management command, or a test that hits the DB directly.
django.db.utils.ProgrammingError: relation "app_thing" does not exist
LINE 1: SELECT ... FROM "app_thing" ...Common causes
Migrations were not applied before the query
The job connects to a fresh database and runs code (or a smoke command) before manage.py migrate, so no tables exist yet.
A management command runs against an unmigrated DB
A step like loaddata or a custom command executes before migrate, hitting tables that are not created.
How to fix it
Run migrate before anything that queries
- Add a
python manage.py migratestep after the DB service is ready. - Run it before seed data, smoke commands, or non-test DB access.
- For the Django test runner, table creation happens automatically inside the test database.
- run: python manage.py migrate --noinputLet the test runner build the schema
Django's test runner applies migrations into the test database automatically; ensure migrations are complete and committed.
python manage.py migrate --check # confirm nothing is pending
python manage.py testHow to prevent it
- Always migrate a fresh database before running commands that query it.
- Keep migrations committed and complete so the schema is reproducible.
- Order CI steps so migrate precedes seed data and smoke checks.