{"record":{"id":"397f21ace347277f","repo":"dbt-labs/dbt-core","slug":"unenforced-constraint-type-type","errorCode":null,"errorMessage":"unenforced constraint type: {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":185,"sourceCode":"    {% do statements.append(stmt) %}\n  {% elif type == 'not_null' %}\n    {% set column_names = constraint.get('columns', []) %}\n    {% if column and not column_names %}\n      {% set column_names = [column['name']] %}\n    {% endif %}\n    {% for column_name in column_names %}\n      {% set column = model.get('columns', {}).get(column_name) %}\n      {% if column %}\n        {% set quoted_name = adapter.quote(column['name']) %}\n        {% set stmt = \"alter table \" ~ relation.render() ~ \" change column \" ~ quoted_name ~ \" set not null \" ~ (constraint.expression or \"\") ~ \";\" %}\n        {% do statements.append(stmt) %}\n      {% else %}\n        {{ exceptions.warn('not_null constraint on invalid column: ' ~ column_name) }}\n      {% endif %}\n    {% endfor %}\n  {% elif type == 'primary_key' %}\n    {% if constraint.get('warn_unenforced') %}\n      {{ exceptions.warn(\"unenforced constraint type: \" ~ type)}}\n    {% endif %}\n    {% set column_names = constraint.get('columns', []) %}\n    {% if column and not column_names %}\n      {% set column_names = [column['name']] %}\n    {% endif %}\n    {% set quoted_names = [] %}\n    {% for column_name in column_names %}\n      {% set column = model.get('columns', {}).get(column_name) %}\n      {% if not column %}\n        {{ exceptions.warn('Invalid primary key column: ' ~ column_name) }}\n      {% else %}\n        {% set quoted_name = adapter.quote(column['name']) %}\n        {% do quoted_names.append(quoted_name) %}\n      {% endif %}\n    {% endfor %}\n\n    {% set joined_names = quoted_names|join(\", \") %}\n    {% set pk_expression = constraint.get('expression') %}","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql#L167-L203","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before (schema.yml)\nconstraints:\n  - type: primary_key\n    columns: [id]\n    warn_unenforced: true\n// after\nconstraints:\n  - type: primary_key\n    columns: [id]\n    warn_unenforced: false","handlingStrategy":"validation","validationCode":"-- dbt schema.yml check before run\n# in CI: grep constraints for warn_unenforced: true on databricks\n# yaml\nmodels:\n  - name: my_model\n    config:\n      constraints:\n        - type: primary_key\n          columns: [id]\n          warn_unenforced: false","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["dbt","jinja","databricks","constraints","primary-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"}