Skip to content
Latchkey

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

  1. Open target/compiled to see the exact SQL dbt sent.
  2. Fix the column name, type cast, or syntax the warehouse flagged.
  3. Re-run just that model with dbt run --select model_name.
Terminal
dbt run --select orders

Add 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 build in CI so a broken model fails before deploy.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →