0
0
DbtDebug / FixBeginner · 3 min read

How to Fix Schema Not Found Error in dbt Quickly

The schema not found error in dbt happens when the target schema does not exist or is misconfigured. To fix it, ensure your dbt_project.yml and profile settings specify the correct schema and that the schema exists in your database.
🔍

Why This Happens

This error occurs because dbt tries to create or access tables in a schema that does not exist or is not accessible. This usually happens when the schema setting in your dbt_project.yml or your profile is incorrect or missing. The database then returns an error saying the schema cannot be found.

yaml
models:
  my_model:
    schema: wrong_schema_name

# Or in profiles.yml
outputs:
  dev:
    schema: wrong_schema_name
Output
Database Error: schema 'wrong_schema_name' does not exist
🔧

The Fix

Update your dbt_project.yml or profiles.yml to use the correct schema name that exists in your database. Also, make sure the schema is created in your database before running dbt models.

yaml
models:
  my_model:
    schema: correct_schema_name

# In profiles.yml
outputs:
  dev:
    schema: correct_schema_name
Output
Running with dbt=1.4.0 Found 1 model, 0 tests, 0 snapshots, 0 analyses, 0 macros, 0 operations, 0 seed files 19:00:00 | Concurrency: 1 threads (target='dev') 19:00:00 | 19:00:00 | 1 of 1 START table model my_model....................... [RUN] 19:00:05 | 1 of 1 OK created table model my_model.................. [OK in 5.0s] 19:00:05 | 19:00:05 | Finished running 1 table model in 6.0s.
🛡️

Prevention

To avoid this error in the future, always verify your schema names in both dbt_project.yml and profiles.yml. Use environment variables to manage schema names for different environments. Also, create schemas in your database before running dbt models. Running dbt debug helps check your connection and schema settings.

⚠️

Related Errors

  • Permission denied on schema: Fix by granting the correct database permissions to your user.
  • Database connection errors: Check your profile credentials and network access.
  • Model not found: Ensure your model files exist and are correctly referenced in dbt_project.yml.

Key Takeaways

Ensure the schema name in dbt configs matches an existing schema in your database.
Create the target schema in your database before running dbt models.
Use dbt debug to verify connection and schema settings.
Manage schema names with environment variables for flexibility.
Check database permissions if you encounter access errors.