dbt build failed error "compilation error: test depends on missing model ref"
Fix the reference, not the test: a test that depends on a missing model ref means the generic or singular test is attached to a model name that does not exist in the project, usually after a rename or a moved file. Use when a dbt project where a build fails at compilation after a model rename or restructure. Not for a source reference that is missing because the source definition was removed, which needs the
TL;DR
Fix the reference, not the test: a test that depends on a missing model ref means the generic or singular test is attached to a model name that does not exist in the project, usually after a rename or a moved file. dbt compiles tests against the manifest graph. A ref to a renamed or deleted model fails the whole build at compilation, before any test runs.
dbt build failed error "compilation error: test depends on missing model ref"Use this when
- The check or run fails with this symptom: a dbt build fails with compilation error test depends on missing model ref.
- You are working on a dbt project where a build fails at compilation after a model rename or restructure and the failure repeats on the same data or configuration.
- You need the failing rows, rule, or stage isolated before changing thresholds or code.
Not for this skill when
- A source reference that is missing because the source definition was removed, which needs the source restored rather than a model ref fix.
- The error text names a different tool, stage, or root cause. Match the verbatim error first and use that skill.
Steps
- Read the compilation error for the exact missing ref name and the file that references it. Verify: the dangling reference is located
- Search the project for the model file and for the old and new names. Verify: the rename or deletion that orphaned the test is confirmed
- Update the test attachment to the current model name, or restore the model if it was deleted by mistake. Verify: dbt parse completes with no missing ref errors
- Run dbt build for the affected model and its tests. Verify: the build compiles and the tests execute
- Run a full dbt parse in CI so future renames fail at review time. Verify: parse is part of the project checks
Variant phrasings
dbt compilation error test depends on missing model ref
The shorter phrasing focused on the named failure.
dbt build failed missing model ref test
The symptom phrasing a searcher tries next.
dbt test ref model renamed compilation fix
The variant naming the failing stage or tool directly.
Compatibility: dbt Core 1.5 and later, generic and singular tests with model refs
Why it happens
Tests attach to models by name in schema files or by ref in singular tests. Renaming a model file updates the model node but not every string that names it, so the first build after a rename surfaces every stale reference at compilation.
Edge cases / pitfalls
- Model renames done by file rename alone also break saved selectors and state selection; search the whole project for the old name, not only schema files.
- A missing ref inside a package points at a version mismatch with the package, not your project; check package pins before editing package tests.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_gwowBDm5RA2kxCB6I05STw