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