# Dbt Model Not Picking Up Source Schema From source.yml File

**URL:** <https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371>\
**Category:** Help\
**Tags:** postgres, dbt-core\
**Created:** [May 13, 2025, 10:08pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371 "2025-05-13T22:08:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![glen.park](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@glen.park](https://discourse.getdbt.com/u/glen.park)\
**Post date:** [May 13, 2025, 10:08pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/1 "2025-05-13T22:08:25Z")

</div>

## The problem I’m having

I have source properties defined in a sources.yml file stored under a subfolder in the models folder that defines the source name, database, schema, and tables. However when I run my dbt model, it keeps defaulting to the information stored in the profile.yml file stored in a separate folder.

## The context of why I’m trying to do this

I have a unique situation where the name of my source schema may change unexpectedly over time so I’m compensating by generating the sources.yml file with updated source information (schema name). So I’m trying to have my dbt models refer to the sources.yml file for that updated schema name using the source() jinja function.

## What I’ve already tried

Example source.yml file code (stored in “/models/sources”)

```auto
version: 1

sources:
  - name: my_source_name
    database: my_source_db
    schema: updated_schema_name123
    tables:
      - name: my_source_table
        identifier: my_source_table123

```

Example profiles.yml code (stored in “/profiles”)

```auto
example_project:
  outputs:
    dev:
      dbname: dev_database
      host: localhost
      pass: my_password
      port: 5432
      schema: default_schema
      threads: 4
      type: postgres
      user: db_user
  target: dev

```

Example dbt model code (model name “my\_test\_model.sql”)

```auto
{{ config(materialized='table') }}

SELECT 
        col1,
	count(*)
FROM {{ source('my_source_name', 'my_source_table') }}
group by col1

```

dbt run command

```auto
dbt run --profiles-dir=/profiles --target dev

```

When running the dbt run command, the result is a new target schema created named “default\_schema\_test\_dbt\_schema” since “test\_dbt\_schema” is defined in dbt\_project.yml. But my expectation is a new target schema named “updated\_schema\_name123\_test\_dbt\_schema” according to [this documentation](https://docs.getdbt.com/docs/build/sources) where referring to the source name should automatically map to the database, schema, and table(s) defined in the sources.yml file. Does the “–profiles-dir” parameter override looking at the sources.yml file somehow.

Thanks,  
Glen

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [May 13, 2025, 10:29pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/2 "2025-05-13T22:29:14Z")

</div>

Source schemas and the schema that dbt writes your models to are different things.

Note: `@Jeremy Yeo` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1747175344050649?thread_ts=1747174128.419879&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![glen.park](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@glen.park](https://discourse.getdbt.com/u/glen.park)\
**Post date:** [May 13, 2025, 10:39pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/3 "2025-05-13T22:39:21Z")

</div>

Ah ok, I guess I misinterpreted the documentation. So the schema defined in the profiles.yml file is meant for destination only and has nothing to do with source schema references. Thanks for the clarification.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [May 13, 2025, 10:59pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/4 "2025-05-13T22:59:45Z")

</div>

You bet.

Note: `@Jeremy Yeo` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1747177173104789?thread_ts=1747174128.419879&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [May 13, 2025, 11:00pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/5 "2025-05-13T23:00:42Z")

</div>

For sources - if the `schema` config is not set on the source - then the schema resolve to the “name” of the source. It does not resolve to the profile.yml schema config at all.

Note: `@Jeremy Yeo` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1747177232438829?thread_ts=1747174128.419879&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![glen.park](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@glen.park](https://discourse.getdbt.com/u/glen.park)\
**Post date:** [May 13, 2025, 11:22pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/6 "2025-05-13T23:22:33Z")

</div>

Interesting, so in my previous source.yml example:

```auto
version: 1

sources:
  - name: my_source_name
    database: my_source_db
    schema: updated_schema_name123
    tables:
      - name: my_source_table
        identifier: my_source_table123

```

You’re saying that if the schema entry “updated\_schema\_name123” did not exist in the yml file, dbt will default to the “name” field, resulting in “my\_source\_name” as the schema it will look for in the source database?

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [May 13, 2025, 11:29pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/7 "2025-05-13T23:29:50Z")

</div>

Yup

Note: `@Jeremy Yeo` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1747178979747619?thread_ts=1747174128.419879&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [May 20, 2025, 11:29pm UTC](https://discourse.getdbt.com/t/dbt-model-not-picking-up-source-schema-from-source-yml-file/19371/8 "2025-05-20T23:29:51Z")

</div>

Closed on May 20, 2025, 11:29pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
