# Redundant Schema name appearing in target db

**URL:** <https://discourse.getdbt.com/t/redundant-schema-name-appearing-in-target-db/9151>\
**Category:** Help\
**Tags:** snowflake\
**Created:** [July 14, 2023, 4:35pm UTC](https://discourse.getdbt.com/t/redundant-schema-name-appearing-in-target-db/9151 "2023-07-14T16:35:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmdbt](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tmdbt](https://discourse.getdbt.com/u/tmdbt)\
**Post date:** [July 14, 2023, 4:35pm UTC](https://discourse.getdbt.com/t/redundant-schema-name-appearing-in-target-db/9151/1 "2023-07-14T16:35:21Z")

</div>

## The problem I’m having

My dbt core project is appending redundant schema name at run time in the target db in Snowflake

In my profiles.yml, my schema is called ‘ORDER\_REPO,’ however at run time, it’s creating an obj named `publish.ORDER_REPO_order_repo.test_gold_billed_orders_v`, with the schema name injected twice.

---

<div class="post-metadata">

**Author:** ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)\
**Post date:** [July 15, 2023, 5:42am UTC](https://discourse.getdbt.com/t/redundant-schema-name-appearing-in-target-db/9151/2 "2023-07-15T05:42:47Z")

</div>

@tmdbt  
looks like u Have defined the schema for model in yml /model file?

dbt by default creates models in \<target\_schema\>\_\<custom\_schema\> to overcome this u have to override the `generate_schema_name` macro

create a sql file generate\_schema\_name.sql and add the below code to it then try to run dbt commands to create models in a given schema

```auto
{% macro generate_schema_name(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if custom_schema_name is none -%}

        {{ default_schema }}

    {%- else -%}

        {{ custom_schema_name | trim }}

    {%- endif -%}

{%- endmacro %}

```

---

<div class="post-metadata">

**Author:** ![paul.chung](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/paul.chung/32/4328_2.png) [@paul.chung](https://discourse.getdbt.com/u/paul.chung)\
**Post date:** [December 11, 2024, 1:51pm UTC](https://discourse.getdbt.com/t/redundant-schema-name-appearing-in-target-db/9151/3 "2024-12-11T13:51:47Z")

</div>

Any thoughts on why dbt docs say do NOT use the code above? To be clear, I’m using the same code you recommended but I haven’t encountered a scenario where the code we use causes issues.

> **[Custom schemas | dbt Developer Hub](https://docs.getdbt.com/docs/build/custom-schemas#warning-dont-replace-default_schema-in-the-macro)**
>
> By default, all dbt models are built in the schema specified in your environment (dbt Cloud) or profile's target (dbt Core). This default schema is called your target schema.
