{"record":{"id":"d413e37da203c02a","repo":"dbt-labs/dbt-core","slug":"constraint-of-type-type-with-no-name-provided","errorCode":null,"errorMessage":"Constraint of type {type} with no `name` provided. Generating hash instead for relation {relation.identifier}","messagePattern":"Constraint of type (.+?) with no `name` provided\\. Generating hash instead for relation (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql","lineNumber":160,"sourceCode":"  {% endfor %}\n\n  {{ return(statements) }}\n{% endmacro %}\n\n{% macro get_constraint_sql(relation, constraint, model, column={}) %}\n  {% set statements = [] %}\n  {% set type = constraint.get('type', '') %}\n\n  {% if type == 'check' %}\n    {% set expression = constraint.get('expression', '') %}\n    {% if not expression %}\n      {{ exceptions.raise_compiler_error('Invalid check constraint expression') }}\n    {% endif %}\n\n    {% set name = constraint.get('name') %}\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 ~ \";\" ~ column.get('name', '') ~ \";\" ~ 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 ~ \" check (\" ~ expression ~ \");\" %}\n    {% 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) %}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql#L142-L178","documentation":"When adding a check constraint, dbt requires a constraint name; if the constraint has no `name`, dbt falls back to generating one from an md5 hash of the relation, column, and expression, and warns about it. If no md5 utility is available it raises a compiler error instead.","triggerScenarios":"Declaring a check constraint (in columns.constraints or model-level constraints with `persist_constraints=true`) without a `name` key on databricks; dbt generates a hashed name and warns.","commonSituations":"Hand-written check constraints missing the `name` field because it is optional in dbt's constraint schema but effectively required by Databricks ALTER TABLE ... ADD CONSTRAINT syntax.","solutions":["Add an explicit `name` to the check constraint definition to get stable, readable constraint names.","If a generated name is acceptable, silence the warning by naming constraints anyway (hash names are opaque and unstable across edits)."],"exampleFix":"# before\n- type: check\n  expression: \"id > 0\"\n# after\n- type: check\n  name: chk_id_positive\n  expression: \"id > 0\"","handlingStrategy":"validation","validationCode":"# Validate constraints in schema.yml before dbt run:\nfor c in model_constraints:\n    if c['type'] == 'check' and not c.get('name'):\n        raise ValueError(f\"check constraint on {model_name} is missing a 'name'\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide an explicit, stable name for check constraints.","Add a CI schema check that rejects unnamed check constraints.","Avoid relying on hash names: they change when expression or column changes, causing DDL churn."],"tags":["dbt","databricks","constraints","naming"],"backgroundTag":"missing-required-config-field","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"}