Skip to content
Latchkey

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
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

  1. Add a python manage.py migrate step after the DB service is ready.
  2. Run it before seed data, smoke commands, or non-test DB access.
  3. For the Django test runner, table creation happens automatically inside the test database.
.github/workflows/ci.yml
- run: python manage.py migrate --noinput

Let the test runner build the schema

Django's test runner applies migrations into the test database automatically; ensure migrations are complete and committed.

Terminal
python manage.py migrate --check  # confirm nothing is pending
python manage.py test

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →