{"record":{"id":"b67c4a728aa1e44f","repo":"dbt-labs/dbt-core","slug":"invalid-constraint-for-column-column-name-o-b67c4a","errorCode":null,"errorMessage":"Invalid constraint for column {{ column_name }}. Only `not_null` is supported.","messagePattern":"Invalid constraint for column (.+?)\\}\\. Only `not_null` is supported\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/dbt-loader/src/dbt_macro_assets/dbt-spark/macros/adapters.sql","lineNumber":231,"sourceCode":"    {% if constraint.type == 'check' and not is_incremental() %}\n      {%- set constraint_hash = local_md5(column_name ~ \";\" ~ constraint.expression ~ \";\" ~ loop.index) -%}\n      {% call statement() %}\n        alter table {{ relation }} add constraint {{ constraint.name if constraint.name else constraint_hash }} check ({{ constraint.expression }});\n      {% endcall %}\n    {% endif %}\n  {% endfor %}\n{% endmacro %}\n\n{% macro alter_column_set_constraints(relation, column_dict) %}\n  {{ return(adapter.dispatch('alter_column_set_constraints', 'dbt')(relation, column_dict)) }}\n{% endmacro %}\n\n{% macro spark__alter_column_set_constraints(relation, column_dict) %}\n  {% for column_name in column_dict %}\n    {% set constraints = column_dict[column_name]['constraints'] %}\n    {% for constraint in constraints %}\n      {% if constraint.type != 'not_null' %}\n        {{ exceptions.warn('Invalid constraint for column ' ~ column_name ~ '. Only `not_null` is supported.') }}\n      {% else %}\n        {% set quoted_name = adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name %}\n        {% call statement() %}\n          alter table {{ relation }} change column {{ quoted_name }} set not null {{ constraint.expression or \"\" }};\n        {% endcall %}\n      {% endif %}\n    {% endfor %}\n  {% endfor %}\n{% endmacro %}\n\n{% macro get_column_comment_sql(column_name, column_dict) -%}\n  {% if column_name in column_dict and column_dict[column_name][\"description\"] -%}\n    {% set escaped_description = column_dict[column_name][\"description\"] | replace(\"'\", \"\\\\'\") %}\n    {% set column_comment_clause = \"comment '\" ~ escaped_description ~ \"'\" %}\n  {%- endif -%}\n  {{ adapter.quote(column_name) }} {{ column_comment_clause }}\n{% endmacro %}\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-loader/src/dbt_macro_assets/dbt-spark/macros/adapters.sql#L213-L249","documentation":"This warning is emitted by the Spark adapter's `spark__alter_column_set_constraints` macro when applying column-level constraints. Spark SQL only supports setting `not null` via `ALTER TABLE ... CHANGE COLUMN ... SET NOT NULL`; any other constraint type (unique, primary key, check, etc.) is skipped and a warning is raised. The model still runs, but the unsupported constraint is silently not enforced.","triggerScenarios":"Defining model-level/column-level `constraints` in a dbt-spark model config with any `type` other than `not_null`, then running the model so the alter-constraints step executes.","commonSituations":"Porting models from Postgres/BigQuery where unique or primary key constraints are declared in schema.yml; teams assuming dbt contract constraints are enforced on Spark.","solutions":["Remove non-`not_null` constraints from the column definition in schema.yml or the model config for Spark models","Keep only `not_null` constraints, which the macro translates to `ALTER TABLE ... SET NOT NULL`","Enforce other constraints at the warehouse/engine level manually (e.g. via post-hook DDL) if the Spark distribution supports them","Wrap constraints in a `contract` with enforced=false so dbt documents them without attempting DDL"],"exampleFix":"// before (schema.yml)\ncolumns:\n  - name: id\n    constraints:\n      - type: not_null\n      - type: unique\n// after\ncolumns:\n  - name: id\n    constraints:\n      - type: not_null","handlingStrategy":"validation","validationCode":"// before running, lint schema.yml constraints for Spark targets\nfunction hasUnsupportedConstraints(constraints) {\n  return (constraints || []).filter(c => c.type !== 'not_null');\n}\nconst unsupported = hasUnsupportedConstraints(column.constraints);\nif (unsupported.length) console.warn('Spark only supports not_null; remove:', unsupported.map(c => c.type));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only declare not_null constraints on Spark models","Move unique/PK declarations into dbt tests (unique, relationships) instead of column constraints","Review constraints when porting models from Postgres/BigQuery to Spark","Use contracts with enforced=false for documentation-only constraints"],"tags":["spark","dbt","constraints","ddl","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}