target problems in profiles.yml

The problem I’m having

I am fully new to dbt
When I try to run “dbt debug” I have this error : Runtime Error
The profile ‘dev’ does not have a target named ‘dev’. The valid target names for this profile are:

  • source
  • bloc_dimensions
  • set_dimensions
  • calculations

See the code of profiles.yml and dbt_project.yml
I explain the context in the next section.

The context of why I’m trying to do this

I have a local postgres server with 3 databases. A source database containing the raw data, another database to store materialized dimension models and another databse that stores others materialized dimensions models.
I want to use the source database to calculate the materialized dimension models and store those tables in a specific database (bloc_dimensions/set_dimensions) of the postgres server. I don’t know if it is a good practice or not.

What I’ve already tried

I tried to setup differents outputs (see the code) on the same profile but I have an error and I don’t really understand why.

Some example code or error messages

profiles.yml
dev:
  target: dev
  outputs:
    source:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: ebay_sales_db
      schema: public
      threads: 4
    bloc_dimensions:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: bloc_db
      threads: 4
    set_dimensions:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: set_db
    calculations:
      type: duckdb
      path: /path/to/your/duckdb/database

prod:
  target: prod
  outputs:
    prod:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: ebay_sales_db
      schema: public
      threads: 4
    bloc_dimensions:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: bloc_db
      threads: 4
    set_dimensions:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: set_db
    calculations:
      type: duckdb
      path: /path/to/your/duckdb/database

dbt_project.yml
name: "dbt_poke_price_tracker"
version: "1.0.0"


profile: "dev"


model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

clean-targets: # directories to be removed by `dbt clean`
  - "target"
  - "dbt_packages"


models:
  dbt_poke_price_tracker:
    staging:
      materialized: view
      +persisted: true 
    
    bloc_dimensions:
      materialized: table
      +persisted: true
      +database: bloc_dimensions

    set_dimensions:
      materialized: table   
      +persisted: true
      +database: set_dimensions 

Hey @jean.guinvarch, at the moment you’re trying to set 3 locations as a single target. You’re also looking for a target named ‘dev’ despite your actual targets in this case being ‘source’, ‘bloc_dimension’ and ‘set_dimensions’. If you change your profiles.yml file to be something like below then you’ll have all 3 targets stored within your ‘dev’ profile. When you need to reference each of these different targets throughout your workflow you can do so using target variables. Some useful info here: About target variables | dbt Developer Hub & Custom target names | dbt Developer Hub.

dev:
  target: source
  outputs:
    source:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: ebay_sales_db
      schema: public
      threads: 4
  target: bloc_dimension
  outputs:
    bloc_dimensions:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: bloc_db
      schema: public
      threads: 4
  target: set_dimensions
  outputs:
    set_dimensions:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: set_db
      schema: public
    calculations:
      type: duckdb
      path: /path/to/your/duckdb/database

Note: I’ve only changed your ‘dev’ profile here. You’ll need to make the same changes for prod otherwise you’ll run into the same error in that env.

1 Like

Hey @jean.guinvarch

If you want some models to be built in a different database, you don’t need to define it in profiles.yml

You can use the database config database | dbt Developer Hub

takes this example

dbt_project.yml

models:
  your_project:
    sales_metrics:
      +database: reporting

Here all models inside models/sales_metrics/ will be built on the reporting database

And you can keep your profiles like

my_profile:
  target: dev
  outputs:
    dev:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: ebay_sales_db
      schema: dev
      threads: 4
    prod:
      type: postgres
      host: localhost
      user: postgres
      pass: Tictact0c!
      port: 5432
      dbname: ebay_sales_db
      schema: prod
      threads: 4
    calculations:
      type: duckdb
      path: /path/to/your/duckdb/database
2 Likes

Thank you ! That what I tried and I think it is working fine. my dbt_project.yml looks like this :

profile: "dev"
          
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

clean-targets: # directories to be removed by `dbt clean`
  - "target"
  - "dbt_packages"


models:
  dbt_poke_price_tracker:
    
    
    staging:
      materialized: view
      +persisted: true 
    
    bloc_dimensions:
      materialized: table
      +persisted: true
      +database: bloc_dimensions

    set_dimensions:
      materialized: table   
      +persisted: true
      +database: set_dimensions 

I set up profiles.yml like this :

dev:
  target: dev
  outputs:
    dev:
      type: postgres
      host: localhost
      user: postgres
      pass: __________
      port: 5432
      dbname: ebay_sales_db
      schema: public
      threads: 4
    duckdb:
      type: duckdb
      path: "dbt_poke_price_tracker/database/ebay_sales.duckdb"
2 Likes

dbt is transformation tool not an ETL tool. In profiles.yml you are confusing profile with target name.
First name dev is profile you are using in dbt_project.yml . Second dev in outputs is the name of your target. dbt will always operate on target database and the only way you can access other postgres db is through some kind of dblink like in oracle.