{"record":{"id":"721e86aba5d48486","repo":"dbt-labs/dbt-core","slug":"unsupported-constraint-type-constraint-type","errorCode":null,"errorMessage":"unsupported constraint type: {{ constraint.type }}","messagePattern":"unsupported constraint type: (.+?)\\}","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql","lineNumber":308,"sourceCode":"    {% set expression = constraint.get('expression', '') %}\n    {% if not expression %}\n      {{ exceptions.raise_compiler_error('Missing custom constraint expression') }}\n    {% endif %}\n\n    {% set name = constraint.get('name') %}\n    {% set expression = constraint.get('expression') %}\n    {% if not name %}\n      {% if local_md5 %}\n        {{ exceptions.warn(\"Constraint of type \" ~ type ~ \" with no `name` provided. Generating hash instead for relation \" ~ relation.identifier) }}\n        {%- set name = local_md5 (relation.identifier ~ \";\" ~ expression ~ \";\") -%}\n      {% else %}\n        {{ exceptions.raise_compiler_error(\"Constraint of type \" ~ type ~ \" with no `name` provided, and no md5 utility.\") }}\n      {% endif %}\n    {% endif %}\n    {% set stmt = \"alter table \" ~ relation.render() ~ \" add constraint \" ~ name ~ \" \" ~ expression ~ \";\" %}\n    {% do statements.append(stmt) %}\n  {% elif constraint.get('warn_unsupported') %}\n    {{ exceptions.warn(\"unsupported constraint type: \" ~ constraint.type)}}\n  {% endif %}\n\n  {{ return(statements) }}\n{% endmacro %}\n\n{% macro databricks_constraints_to_dbt(constraints, column) %}\n  {# convert constraints defined using the original databricks format #}\n  {% set dbt_constraints = [] %}\n  {% for constraint in constraints %}\n    {% if constraint.get and constraint.get('type') %}\n      {# already in model contract format #}\n      {% do dbt_constraints.append(constraint) %}\n    {% else %}\n      {% if column %}\n        {% if constraint == \"not_null\" %}\n          {% do dbt_constraints.append({\"type\": \"not_null\", \"columns\": [column.get('name')]}) %}\n        {% else %}\n          {{ exceptions.raise_compiler_error('Invalid constraint for column ' ~ column.get('name', \"\") ~ '. Only `not_null` is supported.') }}","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql#L290-L326","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the unsupported constraint or move enforcement to a `pre_hook`/post-hook with native Delta DDL","Replace it with a supported type (e.g. `not_null`) where semantically possible","Set `warn_unsupported: false` if the skip is intentional and you want a clean log","Check the dbt-databricks docs for the supported constraint matrix before porting constraints"],"exampleFix":"# before\nconstraints:\n  - type: unique\n    columns: [email]\n# after\nconstraints:\n  - type: not_null\n    columns: [email]\n# or enforce natively:\n# post_hook: \"alter table {{ this }} add constraint uq_email unique (email)\"","handlingStrategy":"validation","validationCode":"SUPPORTED = {'not_null'}  # check adapter docs for full list\ndef check_supported_constraints(model):\n    bad = [c['type'] for c in model.get('constraints', []) if c['type'] not in SUPPORTED]\n    bad += [c['type'] for col in model.get('columns', []) for c in col.get('constraints', []) if c['type'] not in SUPPORTED]\n    assert not bad, f\"{model['name']}: unsupported constraint types {bad}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the dbt-databricks supported-constraints docs before porting constraint YAML from other warehouses","Use dbt tests (unique, relationships) instead of DDL constraints for unsupported types","Set `warn_unsupported` deliberately, not as a blanket default","Scan logs for 'unsupported constraint type' in CI"],"tags":["databricks","constraints","unsupported-feature","jinja"],"backgroundTag":"unsupported-enum-value","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}