Skip to content
Latchkey

Data quality checks: "relation ... does not exist" in CI

A data quality tool queried a table that does not exist yet. In CI this almost always means the quality checks ran before the transforms that build the tables, so the relation has not been created.

What this error means

dbt, Soda, Great Expectations, or a pytest query fails with "relation \"orders\" does not exist" or "Table not found", even though the model exists in the project.

data quality
psycopg2.errors.UndefinedTable: relation "analytics.orders" does not exist
LINE 1: select count(*) from analytics.orders

Common causes

Transforms did not run before quality checks

The workflow ran the quality step before dbt run/dbt build or the extract that creates the table, so the relation is absent.

The check targets the wrong schema or database

The tool points at a schema the CI run did not populate, for example a production target instead of the CI target.

How to fix it

Build transforms before quality checks

  1. Run the models or extracts that create the tables.
  2. Then run the quality checks against them.
  3. Order steps so quality always follows data production.
.github/workflows/ci.yml
- run: dbt build             # create the relations
- run: soda scan -d wh -c configuration.yml checks/orders.yml

Point checks at the CI schema

Ensure the tool config targets the same schema/database the CI transforms wrote to, not a production target.

How to prevent it

  • Sequence data production before quality gates in the workflow.
  • Target the CI schema explicitly in every tool config.
  • Use dbt build so tests run right after their model materializes.

Frequently asked questions

What causes ""relation ... does not exist""?
The workflow ran the quality step before dbt run/dbt build or the extract that creates the table, so the relation is absent.
How do I fix "relation ... does not exist"?
Build transforms before quality checks

Related guides

References

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