Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No database selected #112

Open
hugh-nguyen opened this issue Oct 9, 2022 · 5 comments
Open

No database selected #112

hugh-nguyen opened this issue Oct 9, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@hugh-nguyen
Copy link

Describe the bug

Hi I've just set up a brand new project using db init and dbt-mysql. I've setup my profiles.yaml and checked that dbt debug connects to my database properly and returns no errors.

When I run dbt run, I get the following error
image

How do I specify the database in dbt?

@hugh-nguyen hugh-nguyen added the bug Something isn't working label Oct 9, 2022
@hugh-nguyen
Copy link
Author

Still totally stuck on this, below is a copy of my profiles.yml

puddle:
  target: dev
  outputs:
    dev:
      type: mysql5
      server: localhost
      port: 3306  # optional
      database: puddle
      dbname: puddle
      schema: puddle
      username: test
      password: test
      driver: MySQL ODBC 8.0 ANSI Driver
    prod:
      type: mysql5
      server: [server/host]
      port: [port]  # optional
      database: [schema] # optional, should be same as schema
      schema: [schema]
      username: [username]
      password: [password]
      driver: MySQL ODBC 8.0 ANSI Driver

@hugh-nguyen
Copy link
Author

I've tried adding database/target_database to dbt_project.yml and schema.yml, and in the config of the model
image

@vietvudanh
Copy link

It looks like you have to provide database in SQL query. e.g: <database>.source_data

@4sushi
Copy link

4sushi commented Nov 8, 2022

@hugh-nguyen

You need to use ref() or source() inside your model:

For exemple in your case, you need to transform this query:

select * 
from source_data

into something like:

select *
from {{ source('database', 'table') }}

When you will run this model, dbt will compile the model and the SQL output will be something like:

select *
from `database`.`table`

@rafalitos1234
Copy link

I also had the same problem. Eventually I realized that I was using a non-MySQL function inside my model. Once I changed that, it worked. I think the error message is misleading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants