Home / dbt / Projects and profiles
dbt: Compilation Error: Found a cycle
Found a cycle: model.shop.int_customers --> model.shop.int_orders --> model.shop.int_customersThe ref() calls form a loop, so dbt cannot order the models into a DAG. The message lists the unique ids on the cycle.
Common causes
- Two models reference each other directly or through a chain of models.How to confirm: Follow the unique ids in the message; each one refs the next.
- A model refs itself, often when an incremental model reads its own table with ref() instead of {{ this }}.How to confirm: The cycle contains a single model id.
How to fix it
Break the loop by moving shared logic into a new upstream model that both sides ref.
In incremental models, read the existing table with {{ this }}, not ref() of the same model.
select * from {{ source('app', 'orders') }}
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}Where the message comes from
compilation.pyindbt-labs/dbt-coreatv1.12.6- Message checked in dbt-core 1.12.6
Message template in the source: Found a cycle: %s