dbt "Compilation Error: ambiguous" duplicate model name in CI
dbt found more than one resource with the same name, so a ref() to that name is ambiguous. Model names must be unique across the project (and installed packages) unless you namespace the ref.
What this error means
dbt parse or compile fails with "Compilation Error ... found two resources with the name 'X'. Since these resources have the same name, dbt will be unable to find the correct resource".
dbt
Compilation Error
dbt found two resources with the name "orders". Since these resources have
the same name, dbt will be unable to find the correct resource when
looking for "ref('orders')".Common causes
Two model files produce the same name
Two .sql files in different folders share a filename, so both compete for the same ref() name.
A model name collides with a package model
A local model and a model in an installed package share a name, making an unqualified ref ambiguous.
How to fix it
Rename one resource to be unique
- Find the two files dbt names in the error.
- Rename one so every resource name is unique in the project.
- Update refs to the renamed model and re-run
dbt compile.
Terminal
dbt ls --resource-type model | sort | uniq -dNamespace a ref to a package model
When the collision is with a package, qualify the ref with the package name to disambiguate.
models/marts/orders.sql
-- ref the package model explicitly
select * from {{ ref('my_package', 'orders') }}How to prevent it
- Keep every model, seed, and source name unique across the project.
- Namespace refs when a package intentionally shares a name.
- Run
dbt parsein CI to catch duplicates before build.
Related guides
dbt Compilation Error: model depends on a node not found (ref) in CIFix dbt "Compilation Error: Model X depends on a node named Y which was not found" in CI - a ref() points at…
dbt "Compilation Error: macro not found" in CIFix dbt "Compilation Error: macro X not found" in CI - a model or config calls a macro that is not defined in…
dbt "Compilation Error: found a cycle" circular ref in CIFix dbt "Compilation Error: Found a cycle" in CI - two or more models ref() each other, creating a circular d…