dbt-labs/dbt-core · warning
unenforced constraint type: {type}
Error message
unenforced constraint type: {type} What it means
This is a dbt compile-time warning (exceptions.warn, not a raise) emitted by the Databricks constraint macro when processing a primary_key constraint whose `warn_unenforced` flag is set. Databricks does not actually enforce primary key constraints at write time (they are informational only for the optimizer), so the macro warns the user that the constraint will be rendered as DDL but will not prevent bad data. It is informational and compilation continues.
Source
Thrown at crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql:185
{% do statements.append(stmt) %}
{% elif type == 'not_null' %}
{% set column_names = constraint.get('columns', []) %}
{% if column and not column_names %}
{% set column_names = [column['name']] %}
{% endif %}
{% for column_name in column_names %}
{% set column = model.get('columns', {}).get(column_name) %}
{% if column %}
{% set quoted_name = adapter.quote(column['name']) %}
{% set stmt = "alter table " ~ relation.render() ~ " change column " ~ quoted_name ~ " set not null " ~ (constraint.expression or "") ~ ";" %}
{% do statements.append(stmt) %}
{% else %}
{{ exceptions.warn('not_null constraint on invalid column: ' ~ column_name) }}
{% endif %}
{% endfor %}
{% elif type == 'primary_key' %}
{% if constraint.get('warn_unenforced') %}
{{ exceptions.warn("unenforced constraint type: " ~ type)}}
{% endif %}
{% set column_names = constraint.get('columns', []) %}
{% if column and not column_names %}
{% set column_names = [column['name']] %}
{% endif %}
{% set quoted_names = [] %}
{% for column_name in column_names %}
{% set column = model.get('columns', {}).get(column_name) %}
{% if not column %}
{{ exceptions.warn('Invalid primary key column: ' ~ column_name) }}
{% else %}
{% set quoted_name = adapter.quote(column['name']) %}
{% do quoted_names.append(quoted_name) %}
{% endif %}
{% endfor %}
{% set joined_names = quoted_names|join(", ") %}
{% set pk_expression = constraint.get('expression') %}View on GitHub (pinned to 0267ce9170)
Solutions
- Accept the warning: it is informational; the primary key is still emitted as DDL for the Databricks optimizer.
- Set `warn_unenforced: false` on the constraint config to silence the warning when you know PKs are unenforced on Databricks.
- Replace the primary_key constraint with dbt tests (e.g. unique/not_null generic tests) if you need actual enforcement of uniqueness.
- Remove the primary_key constraint if it serves no purpose for your Databricks workload.
Example fix
// before (schema.yml)
constraints:
- type: primary_key
columns: [id]
warn_unenforced: true
// after
constraints:
- type: primary_key
columns: [id]
warn_unenforced: false Defensive patterns
Strategy: validation
Validate before calling
-- dbt schema.yml check before run
# in CI: grep constraints for warn_unenforced: true on databricks
# yaml
models:
- name: my_model
config:
constraints:
- type: primary_key
columns: [id]
warn_unenforced: false Prevention
- Know your adapter's enforcement matrix: Databricks PK/FK are informational only.
- Set warn_unenforced: false project-wide once reviewed to keep logs clean.
- Back constraints with dbt tests (unique, not_null) for real enforcement.
- Treat warn output as audit signal during migrations, not errors.
When it happens
Trigger: A model defines a `primary_key` constraint (in `constraints` on the model or a column) with `warn_unenforced: true` on an adapter (dbt-databricks) where the constraint is not enforced; the constraints macro at constraints.sql:184-186 then warns during `dbt run`/`dbt build`.
Common situations: Porting a model from Postgres/Snowflake (where PKs are enforced) to Databricks; teams enabling warn_unenforced to audit constraint support; copying generic tests/constraints from core dbt examples that assume enforcement.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Invalid primary key column: {column_name}
- unenforced constraint type: {constraint.type}
- Constraint of type {{ type }} with no `name` provided. Gener
- Constraints not supported for file format: {adapter.resolve_
- Constraint of type {type} with no `name` provided. Generatin
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/397f21ace347277f.
Report an issue: GitHub.