{"record":{"id":"29fe93e643e50283","repo":"dbt-labs/dbt-core","slug":"constraints-not-supported-for-file-format-adapte","errorCode":null,"errorMessage":"Constraints not supported for file format: {adapter.resolve_file_format(config)}","messagePattern":"Constraints not supported for file format: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql","lineNumber":14,"sourceCode":"{# Persist table-level and column-level constraints. #}\n{% macro persist_constraints(relation, model) %}\n  {{ return(adapter.dispatch('persist_constraints', 'dbt')(relation, model)) }}\n{% endmacro %}\n\n{% macro databricks__persist_constraints(relation, model) %}\n  {%- set contract_config = config.get('contract') -%}\n  {% set has_model_contract = contract_config and contract_config.enforced %}\n  {% set has_databricks_constraints = config.get('persist_constraints', False) %}\n\n  {% if (has_model_contract or has_databricks_constraints) %}\n    {% if adapter.resolve_file_format(config) != 'delta' %}\n      {# Constraints are only supported for delta tables #}\n      {{ exceptions.warn(\"Constraints not supported for file format: \" ~ adapter.resolve_file_format(config)) }}\n    {% elif relation.is_view %}\n      {# Constraints are not supported for views. This point in the code should not have been reached. #}\n      {{ exceptions.raise_compiler_error(\"Constraints not supported for views.\") }}\n    {% elif is_incremental() %}\n      {# Constraints are not applied for incremental updates. This point in the code should not have been reached #}\n      {{ exceptions.raise_compiler_error(\"Constraints are not applied for incremental updates. Full refresh is required to update constraints.\") }}\n    {% else %}\n      {#- DIVERGENCE BEGIN: drop any PK inherited from a SHALLOW CLONE before applying\n          model constraints. SHALLOW CLONE preserves and renames the source's primary key,\n          so a subsequent ALTER TABLE ADD CONSTRAINT fails with \"table already has a PRIMARY\n          KEY constraint\". Upstream dbt-databricks is not affected because it does not use\n          SHALLOW CLONE. Only applicable to Unity Catalog (not Hive Metastore).\n          Gated on dbt_version: under dbt-core (1.x) SHALLOW CLONE is not used, so no-op. -#}\n      {% if dbt_version.startswith('2.') and not relation.is_hive_metastore() %}\n        {% set existing_pks = fetch_primary_key_constraints(relation) %}\n        {% if existing_pks.rows | length > 0 %}\n          {% for row in existing_pks %}\n            {% if loop.first %}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-loader/src/dbt_macro_assets/dbt-databricks/macros/relations/constraints.sql#L1-L32","documentation":"Databricks only supports model constraints (contracts or persisted constraints) on Delta tables. When the model has an enforced contract or `persist_constraints=true` but `adapter.resolve_file_format(config)` resolves to something other than `delta` (e.g. parquet, csv, json), dbt warns that the constraints will not be applied and skips them.","triggerScenarios":"A model with `contract={enforced: true}` or `config.get('persist_constraints')=true` combined with a `file_format` that is not `delta` (e.g. `file_format='parquet'`) in the databricks table materialization.","commonSituations":"Converting a model from parquet to delta while keeping constraint declarations; copying constraint config into a model that writes external/non-delta tables; org-wide contract enforcement applied to heterogeneous-format models.","solutions":["Set `file_format='delta'` in the model config so the constraints can be enforced.","Remove the constraint/contract declarations if the non-delta format is intentional.","Run with `--full-refresh` after switching to delta so the table is recreated in the new format."],"exampleFix":"-- before\n{{ config(materialized='table', file_format='parquet', persist_constraints=true) }}\n-- after\n{{ config(materialized='table', file_format='delta', persist_constraints=true) }}","handlingStrategy":"validation","validationCode":"# Validate before running:\nif (config.get('persist_constraints') or config.get('contract', {}).get('enforced')) and config.get('file_format') != 'delta':\n    raise ValueError('constraints require file_format=delta')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on file_format='delta' for any model declaring contracts or constraints.","Lint schema.yml for contract/constraint usage alongside non-delta file formats.","Remember constraints only apply on create/full-refresh, not incremental runs."],"tags":["dbt","databricks","constraints","delta","file-format"],"backgroundTag":"unsupported-operation","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"}