{"record":{"id":"8c502194c6b1a9b3","repo":"dbt-labs/dbt-core","slug":"unenforced-constraint-type-constraint-type","errorCode":null,"errorMessage":"unenforced constraint type: {constraint.type}","messagePattern":"unenforced 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":224,"sourceCode":"    {% 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 hash_input = \"primary_key;\" ~ relation.identifier ~ \";\" ~ column_names ~ \";\" -%}\n        {%- if pk_expression -%}\n          {%- set hash_input = hash_input ~ pk_expression ~ \";\" -%}\n        {%- endif -%}\n        {%- set name = local_md5(hash_input) -%}\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 pk_suffix = (\" \" ~ pk_expression) if pk_expression else \"\" %}\n    {% set stmt = \"alter table \" ~ relation.render() ~ \" add constraint \" ~ name ~ \" primary key(\" ~ joined_names ~ \")\" ~ pk_suffix ~ \";\" %}\n    {% do statements.append(stmt) %}\n  {% elif type == 'foreign_key' %}\n\n    {% if constraint.get('warn_unenforced') %}\n      {{ exceptions.warn(\"unenforced constraint type: \" ~ constraint.type)}}\n    {% endif %}\n\n    {% set name = constraint.get('name') %}\n    \n    {% if constraint.get('expression') %}\n\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(\"foreign_key;\" ~ relation.identifier ~ \";\" ~ constraint.get('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\n      {% set stmt = \"alter table \" ~ relation.render() ~ \" add constraint \" ~ name ~ \" foreign key\" ~ constraint.get('expression') %}\n    {% else %}\n      {% set column_names = constraint.get('columns', []) %}","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql#L206-L242","documentation":"A warning mirroring error 785 but for foreign_key constraints: when a foreign_key constraint sets `warn_unenforced: true` and the adapter (Databricks) does not enforce foreign keys, the macro warns using `constraint.type` before rendering the ADD CONSTRAINT statement. Databricks foreign keys are declarative only (used by the optimizer for join pruning), not enforced on writes. Compilation continues normally.","triggerScenarios":"A model defines a `foreign_key` constraint with `warn_unenforced: true` (model-level constraints or `contract.enforced`-adjacent configs) on dbt-databricks; the branch at constraints.sql:222-225 fires during compile/run.","commonSituations":"Migrating FK-enforcing warehouses (Postgres, SQL Server) to Databricks; enabling warn_unenforced to discover which constraints are silently unenforced; inherited configs where warn_unenforced defaults on for foreign keys.","solutions":["Set `warn_unenforced: false` on the foreign_key constraint to silence it once you accept Databricks does not enforce FKs.","Keep the warning while auditing, then disable it project-wide via constraint config defaults.","Enforce referential integrity in-pipeline with dbt tests (relationships test) instead of relying on the DDL constraint.","Remove the foreign_key constraint if declarative-only metadata provides no value for your workload."],"exampleFix":"// before\n- type: foreign_key\n  to: ref('parent')\n  warn_unenforced: true\n// after\n- type: foreign_key\n  to: ref('parent')\n  warn_unenforced: false","handlingStrategy":"validation","validationCode":"# CI check: no unenforced FK warnings on databricks\n# dbt build --select ... 2>&1 | grep 'unenforced constraint type' && exit 1\n# or set defaults:\n# dbt_project.yml\nmodels:\n  +constraints:\n    - type: foreign_key\n      warn_unenforced: false","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default warn_unenforced to false for FK/PK on Databricks projects.","Use dbt relationships tests for actual referential-integrity checking.","Review warnings once during warehouse migration, then silence.","Remember Databricks FKs aid the optimizer only; do not rely on them for data quality."],"tags":["dbt","jinja","databricks","constraints","foreign-key"],"backgroundTag":"unsupported-operation","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}