Skip to content
Latchkey

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

  1. Find the two files dbt names in the error.
  2. Rename one so every resource name is unique in the project.
  3. Update refs to the renamed model and re-run dbt compile.
Terminal
dbt ls --resource-type model | sort | uniq -d

Namespace 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 parse in CI to catch duplicates before build.

Related guides

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