dbt-labs/dbt-core · warning

unsupported constraint type: {{ constraint.type }}

Error message

unsupported constraint type: {{ constraint.type }}

What it means

Databricks only supports a subset of dbt constraint types in its DDL generation. When a model declares a constraint whose `type` is not one the adapter implements, and the constraint (or config) has `warn_unsupported` enabled, dbt warns and skips generating DDL for it rather than failing. The constraint is silently dropped from the output SQL otherwise/afterwards.

Source

Thrown at crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql:308

    {% set expression = constraint.get('expression', '') %}
    {% if not expression %}
      {{ exceptions.raise_compiler_error('Missing custom constraint expression') }}
    {% endif %}

    {% set name = constraint.get('name') %}
    {% set expression = constraint.get('expression') %}
    {% if not name %}
      {% if local_md5 %}
        {{ exceptions.warn("Constraint of type " ~ type ~ " with no `name` provided. Generating hash instead for relation " ~ relation.identifier) }}
        {%- set name = local_md5 (relation.identifier ~ ";" ~ expression ~ ";") -%}
      {% else %}
        {{ exceptions.raise_compiler_error("Constraint of type " ~ type ~ " with no `name` provided, and no md5 utility.") }}
      {% endif %}
    {% endif %}
    {% set stmt = "alter table " ~ relation.render() ~ " add constraint " ~ name ~ " " ~ expression ~ ";" %}
    {% do statements.append(stmt) %}
  {% elif constraint.get('warn_unsupported') %}
    {{ exceptions.warn("unsupported constraint type: " ~ constraint.type)}}
  {% endif %}

  {{ return(statements) }}
{% endmacro %}

{% macro databricks_constraints_to_dbt(constraints, column) %}
  {# convert constraints defined using the original databricks format #}
  {% set dbt_constraints = [] %}
  {% for constraint in constraints %}
    {% if constraint.get and constraint.get('type') %}
      {# already in model contract format #}
      {% do dbt_constraints.append(constraint) %}
    {% else %}
      {% if column %}
        {% if constraint == "not_null" %}
          {% do dbt_constraints.append({"type": "not_null", "columns": [column.get('name')]}) %}
        {% else %}
          {{ exceptions.raise_compiler_error('Invalid constraint for column ' ~ column.get('name', "") ~ '. Only `not_null` is supported.') }}

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Remove the unsupported constraint or move enforcement to a `pre_hook`/post-hook with native Delta DDL
  2. Replace it with a supported type (e.g. `not_null`) where semantically possible
  3. Set `warn_unsupported: false` if the skip is intentional and you want a clean log
  4. Check the dbt-databricks docs for the supported constraint matrix before porting constraints

Example fix

# before
constraints:
  - type: unique
    columns: [email]
# after
constraints:
  - type: not_null
    columns: [email]
# or enforce natively:
# post_hook: "alter table {{ this }} add constraint uq_email unique (email)"
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {'not_null'}  # check adapter docs for full list
def check_supported_constraints(model):
    bad = [c['type'] for c in model.get('constraints', []) if c['type'] not in SUPPORTED]
    bad += [c['type'] for col in model.get('columns', []) for c in col.get('constraints', []) if c['type'] not in SUPPORTED]
    assert not bad, f"{model['name']}: unsupported constraint types {bad}"

Prevention

When it happens

Trigger: Declaring a constraint type the Databricks adapter does not implement (e.g. `unique`, `primary_key`, `custom` in positions it doesn't handle) in model/column YAML while `warn_unsupported: true` is set.

Common situations: Copying constraint YAML from a Postgres/SQL Server project into a Databricks project; assuming all core constraint types are enforced on Delta; enabling `contract.enforced` expecting all constraints to be applied.

Related errors


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/721e86aba5d48486. Report an issue: GitHub.