Modelling correctness · rule catalog-phantom-column
dbt YAML columns missing from the warehouse
A Metacenta review checks this under the rule Declared columns exist in the warehouse. Everything below applies whether or not you ever commission one.
What this rule checks
This rule flags models whose schema YAML declares a column the built relation does not have. Names are compared ignoring case. A relation for which the catalog lists no columns is skipped, as is a model not in the catalog.
Why it matters
A test or contract on a missing column protects nothing. The documentation also describes a shape the data does not have, so readers plan queries against columns that are not there.
How to fix it
Reconcile the declared columns with the ones that exist. Select the column in the model, or remove it from the schema YAML along with the tests that name it.
Before:
models:
- name: fct_orders
columns:
- name: order_id
- name: discount_code
data_tests:
- not_null
After:
models:
- name: fct_orders
columns:
- name: order_id
When it is fine to leave
A column added to YAML ahead of the model change that selects it is fine for as long as that change is in flight. Build it before the tests are relied on.
What we need to check it
manifest.json and catalog.json, generated together by dbt docs generate. If the catalog is older than the manifest, a missing column could be an unbuilt change, so the rule declines.