dbt-labs/dbt-core · error

Relations should always come with a defined schema. Missing…

Error message

Relations should always come with a defined schema. Missing schema for {relation.identifier}

What it means

Warning emitted by the dbt-clickhouse get_columns_in_relation macro path: a relation being introspected has an identifier but no schema, which should never happen for properly resolved ClickHouse relations. The relation identifier is interpolated; the fault is a relation object built without a schema component.

Solutions

  1. Ensure the target/profile defines a schema so generated relations always carry one
  2. Check custom schema macros that may strip the schema from relation objects
  3. Verify the relation was created via the adapter's relation factory rather than ad-hoc
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/dbt-loader/src/dbt_macro_assets/dbt-clickhouse/macros/adapters.sql:121 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/0a6dd53c164b32a5. Report an issue: GitHub.

Appendix: source

Thrown at crates/dbt-loader/src/dbt_macro_assets/dbt-clickhouse/macros/adapters.sql:121

      {% endif %}
        join system.databases as db on t.database = db.name
        left join mv_sources on mv_sources.target_fqn = concat(t.database, '.', t.name)
      where schema = '{{ schema_relation.schema }}'
      group by name, schema, type, db_engine

  {% endcall %}
  {{ return(load_result('list_relations_without_caching').table) }}
{% endmacro %}

{% macro clickhouse__get_columns_in_relation(relation) -%}
  {% call statement('get_columns', fetch_result=True) %}
    select name, type from system.columns where table = '{{ relation.identifier }}'
    {% if relation.schema %}
      {% if not relation.is_temporary %}
        and database = '{{ relation.schema }}'
      {% endif %}
    {% else %}
      {% do exceptions.warn("Relations should always come with a defined schema. Missing schema for " ~ relation.identifier) %}
    {% endif %}
    order by position
  {% endcall %}
  {{ return(sql_convert_columns_in_relation(load_result('get_columns').table)) }}
{% endmacro %}

{% macro clickhouse__drop_relation(relation, obj_type='table') -%}
  {% call statement('drop_relation', auto_begin=False) -%}
    drop {{ obj_type }} if exists {{ relation }} {{ on_cluster_clause(relation, True)}}
  {%- endcall %}
{% endmacro %}

{% macro clickhouse__rename_relation(from_relation, to_relation, obj_type='table') -%}
  {% call statement('drop_relation') %}
    drop {{ obj_type }} if exists {{ to_relation }} {{ on_cluster_clause(to_relation)}}
  {% endcall %}
  {% call statement('rename_relation') %}
    rename {{ obj_type }} {{ from_relation }} to {{ to_relation }} {{ on_cluster_clause(from_relation)}}

View on GitHub (pinned to 0267ce9170)