Skip to content
Latchkey

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.

psql
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

Terminal
python manage.py migrate --noinput
python manage.py loaddata fixtures.json   # only after migrate
python manage.py test

Ensure the model has a migration

  1. Run makemigrations for the app and commit the result.
  2. Confirm CI runs migrate against the same database the code uses.
  3. Order setup so migrate precedes any query or fixture load.

How to prevent it

  • Always migrate before tests, fixtures, or seeding.
  • Add makemigrations --check so missing migrations fail fast.
  • This is deterministic - retrying without migrating fails identically.

Frequently asked questions

What causes ""ProgrammingError: relation does not exist""?
A data load, fixture, or test queried the table before migrate created it.
How do I fix "ProgrammingError: relation does not exist"?
Apply migrations before anything queries the schema

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card