dbt "Database Error in model" SQL error in CI
dbt compiled the model and the warehouse rejected the resulting SQL. The message wraps the database driver error: a missing column, a type mismatch, or a syntax error the engine reported.
What this error means
dbt run or build marks a model as ERROR with "Database Error in model X" and the warehouse message, such as "column \"y\" does not exist" or "syntax error at or near".
dbt
Database Error in model orders (models/marts/orders.sql)
column "custmer_id" does not exist
LINE 3: select custmer_id, amount from {{ ref('stg_orders') }}Common causes
The SQL references a column or type the warehouse rejects
A misspelled column, a type mismatch, or invalid syntax makes the compiled query fail on the engine.
An upstream model changed its schema
A ref'd model no longer produces a column this model selects, so the query fails at run time.
How to fix it
Read the warehouse error and fix the SQL
- Open target/compiled to see the exact SQL dbt sent.
- Fix the column name, type cast, or syntax the warehouse flagged.
- Re-run just that model with
dbt run --select model_name.
Terminal
dbt run --select ordersAdd a data test to catch schema drift
Enforce expected columns with tests so an upstream change fails a test instead of a downstream model.
Terminal
dbt build --select stg_orders+How to prevent it
- Inspect target/compiled SQL when a Database Error appears.
- Add not_null / relationships tests to catch upstream schema changes.
- Run
dbt buildin CI so a broken model fails before deploy.
Related guides
dbt "Runtime Error: relation does not exist" in CIFix dbt "Database Error ... relation X does not exist" in CI - a model or test queries a table or view that w…
dbt test failure (unique / not_null) fails CI with exit 1Fix a dbt data test failure (unique, not_null) in CI - the model data violated a test assertion, so dbt exits…
dbt "Compilation Error: X is undefined" Jinja var in CIFix dbt "Compilation Error ... 'X' is undefined" in CI - a model references a Jinja variable or var() that is…