In dbt cloud, I tried to create model ‘A’ in database ‘X’ by referencing model ‘B’ in database ‘Y’ (created in the same dbt project) with the ref function. However, when I run dbt run, it tries to reference model ‘B’ in database ‘X’ and I get an error.
Can I use the ref function only for models in the same database?
If I want to reference a model in a different database, do I need to use the source function?
I’m kind of new, but I’d expect you’d need a source set in dbt to reference database ‘Y’. Assuming you have that, maybe it’d help if you posted the code you’re using to create model ‘A’?
In dbt cloud, after deploying model ‘B’ to database ‘Y’ in one job, the following error occurred when deploying model ‘A’ to database ‘X’ in another job.
08:28:34 002003 (42S02): SQL compilation error:
08:28:34 Object ‘< Database ‘X’ >. < Schema >.< Model ‘B’ >’ does not exist or not authorized.
Also, the code for model ‘A’ is as simple as
> with final as (
> select
> id,
> created_date
> from {{ ref('b') }}
> )
>
> select * from final