How to overwrite schema set in `profile.yml`?

I have given a different schema for a model in dbt_project.yml but it is still creating my views in the schema mentioned in profile.yml. I do not think it is the expected behavior or is it?
dbt version 0.20.2

1 Like

Any chance that there is yml in the subfolders specified the same schema?

No there is not. I checked it.
This is how my dbt_project.yml looks like :

# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'abc'
version: '1.0.0'
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'raaj'

# These configurations specify where dbt should look for different types of files.
# The `source-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target"  # directory which will store compiled SQL files
clean-targets:         # directories to be removed by `dbt clean`
    - "target"
    - "dbt_modules"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/ directory
# as tables. These settings can be overridden in the individual model files
# using the `{{ config(...) }}` macro.
models:
  abc:
    myschema:
      +materialized: view
      +schema: myschema
      +bind: false

This is how my ~./dbt/profiles.yaml looks like

raaj:
  target: dev  
  outputs:
    dev:
      type: redshift
      threads: 4
      host: xxx
      port: 5439
      user: xxx
      password: xxx
      dbname: xxx
      schema: dbt_raaj
      keepalives_idle: 0
    prod:
      type: redshift
      threads: 4
      host: xxx
      port: 5439
      user: xxx
      password: xxx
      dbname: xxx
      schema: myschema
      keepalives_idle: 0

Hi Raaj, just 2 cents from me:

have you checked if there is any other .yml file in the subfolders of which will overrides the schema in the upper level?

Also refer to ... your dbt runs should instead target an existing schema that your user has permission to create relations within., it may pays to check the existence of the schema myschema and the owner role of that schema…

Deploy to custom schemas & override dbt defaults - YouTube I found this very helpful.

2 Likes