{"record":{"id":"05a061a9b1a0a50c","repo":"dbt-labs/dbt-core","slug":"constraint-of-type-type-with-no-name-provi","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":233,"sourceCode":"        {{ 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', []) %}\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 foreign key column: ' ~ column_name) }}\n        {% else %}","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql#L215-L251","documentation":"Like error 787 but on the foreign_key-with-expression path: when a foreign_key constraint supplies an `expression` (e.g. `(id) references parent(id)`) but no `name`, and `local_md5` is available, the macro warns and generates the constraint name as `md5(\"foreign_key;<identifier>;<expression>;\")`. Without md5 it would instead raise a compiler error; here compilation succeeds with a hash name.","triggerScenarios":"A foreign_key constraint with `expression` set but `name` omitted, processed at constraints.sql:231-234 while `local_md5` exists; e.g. `constraints: [{type: foreign_key, expression: \"(user_id) REFERENCES schema.parent(id)\"}]`.","commonSituations":"Hand-written FK expressions copied from DDL without names; dbt-codegen or migration tooling emitting expression-only constraints; older dbt versions that did not require `name` on constraints.","solutions":["Add an explicit `name` field to the foreign_key constraint for a stable, readable name.","Accept the warning; the md5-derived name is deterministic for identical identifier+expression.","If the generated name changes when the expression is edited, pin a `name` to keep the constraint identity stable across refactors.","Ensure the adapter exposes local_md5 — if it is missing this same condition raises a compiler error instead."],"exampleFix":"// before\n- type: foreign_key\n  expression: \"(user_id) REFERENCES parent(id)\"\n// after\n- type: foreign_key\n  name: fk_child_user\n  expression: \"(user_id) REFERENCES parent(id)\"","handlingStrategy":"validation","validationCode":"import yaml\ncfg = yaml.safe_load(open('models/schema.yml'))\nfor m in cfg['models']:\n    for c in m.get('constraints', []):\n        if c['type'] == 'foreign_key' and c.get('expression') and not c.get('name'):\n            raise ValueError(f\"foreign_key constraint on {m['name']} needs a name\")","typeGuard":"def fk_is_named(c: dict) -> bool:\n    return not c.get('expression') or bool(c.get('name'))","tryCatchPattern":null,"preventionTips":["Pair every foreign_key expression with an explicit name.","Lint schema.yml in CI to reject unnamed constraints.","Pin names to survive expression refactors without constraint identity churn.","Verify the adapter provides local_md5, otherwise this becomes a compiler error."],"tags":["dbt","jinja","databricks","constraints","foreign-key"],"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"}