MetricSign
EN|NLRequest Access
High severitydata_quality

Power BI Refresh Error:
DbtModelConstraintViolation

What does this error mean?

A dbt model defined with contract constraints (not_null, unique, primary_key, foreign_key) failed because the materialized data violates one or more of those constraints.

Common causes

  • 1Upstream data changes introduced null values in a column declared as not_null in the model contract
  • 2A deduplication step was removed or failed, causing unique constraint violations
  • 3A foreign key reference points to a parent row that no longer exists in the referenced model
  • 4The model contract was defined after bad data was already present in the table

How to fix it

  1. 1Step 1: Run dbt test --select model_name to identify which constraint test failed.
  2. 2Step 2: Inspect the failing rows: run the model's compiled SQL and filter for null or duplicate values in the constrained column.
  3. 3Step 3: Fix the upstream transformation that introduced the bad data.
  4. 4Step 4: If the constraint is too strict for the data, discuss relaxing it or adding data cleaning logic in the model.
  5. 5Step 5: Add a pre-hook to validate data quality before materializing to catch violations earlier in the run.

Frequently asked questions

Are dbt model-level constraints the same as dbt tests?

No — model-level constraints (in the contract block) define expectations about the model's output schema and are enforced at materialization time. dbt tests are separate assertions run after materialization with dbt test.

Which data warehouses enforce dbt model constraints at the database level?

Snowflake (not_null, unique), BigQuery (not_null), and Databricks (not_null) can enforce some constraints at the warehouse level. Redshift enforces them only as metadata. Always pair constraints with dbt tests for reliable enforcement.

Other data_quality errors