dbt not_null / relationships test failure in CI
A dbt not_null test found nulls in a column that must be populated, or a relationships test found values with no matching parent key. Both fail because dbt is configured to fail when the offending row count is not zero.
What this error means
A dbt test step fails with "Failure in test not_null_<model>_<column>" or "relationships_<model>_<column>" and "Got N results, configured to fail if != 0".
Failure in test relationships_orders_customer_id__id__ref_customers_
Got 23 results, configured to fail if != 0
23 orders reference a customer_id that does not exist in customersCommon causes
Missing or orphaned values
A not_null column has nulls, or a relationships foreign key points at rows absent from the parent, usually from incomplete upstream data.
Tests ran before dependencies were built
The referenced parent model was not built in CI, so every child row looks orphaned.
How to fix it
Build dependencies then test
- Use
dbt buildso parents are materialized before relationship tests run. - Inspect failing rows with
--store-failures. - Fix the upstream data or the join producing nulls or orphans.
dbt build --select +orders # build parents, then run its testsCorrect the constraint if it is too strict
If nulls are legitimately allowed, drop not_null; if orphans are expected during a window, relax the relationships test or filter it.
- relationships:
to: ref('customers')
field: id
config:
where: "created_at < current_date"How to prevent it
- Prefer
dbt buildso tests run after their dependencies. - Store failures to inspect the exact offending rows.
- Keep constraints honest to the real data contract.