Compilation Error dbt found two models with the name

Hi Experts,

My Requirement : I need to have two models with same name but in different schema. One is a table and other is a view. when i run
"dbt run --models models/BASE/CV_DM_PRODLO.sql " specific model in my termial

I am seeing below error:
Encountered an error:
Compilation Error
dbt found two models with the name “CV_DM_PRODLO”.

Since these resources have the same name, dbt will be unable to find the correct resource
when looking for ref(“CV_DM_PRODLO”).

To fix this, change the name of one of these resources:

  • model.QSA.CV_DM_PRODLO (models\VIRTUAL\CV_DM_PRODLO.sql)
  • model.QSA.CV_DM_PRODLO (models\BASE\CV_DM_PRODLO.sql)

You appear to have stated your own fix - you must change the name of one of the models?

There is no way of having two models with the same name in DBT, even if they in different folders that represent two different schemas, and are going to end up in different schemas in the target database (which would be allowed in most if not all SQL databases).

I can understand why you would have this requirement too - I assume adherence to a naming convention for starters. But yeah it’s a limitation you would only be able to get around by having separate DBT projects I believe.

1 Like

Thanks SignalRunner. :slightly_smiling_face:

Tried and below is the approach.
1.Renamed the sql files so that it can be unique.
* model.QSA.CV_DM_PRODLO _VIRTUAL.sql
* model.QSA.CV_DM_PRODLO _BASE.sql
2.added ‘ALIAS’ inside the sql file
* {{ config(materialized=‘view’, alias=‘CV_DM_PRODLO’, schema=‘VIRTUAL’) }}
* {{ config(materialized=‘table’, alias=‘CV_DM_PRODLO’, schema=‘BASE’) }}
By this achieved , same artifact name in two different schemas.

Thanks,
Madhavan