Primary key inference
Datafold looks for the primary key of each dbt model in this order and uses the first match:- Model-level
metawith the primary key tag - Column-level
metawith the primary key tag - Column-level tags
- dbt uniqueness tests
- The
unique_keyconfig (for incremental models and snapshots) - Column-name guesses:
id,pk,pkey, or<model_name>_id - dbt
primary_keyconstraints
primary-key. You can change it with the Primary key tag setting in your dbt CI integration.
Metadata
The first option is setting theprimary-key key in the dbt metadata. There are several ways to configure this in your dbt project using either the meta key in a yaml file or a model-specific config block.
You can list the primary key columns at the model level:
Tags
If the primary key is not found in the metadata, it will go through the tags.Inferred
If the primary key isn’t provided explicitly, Datafold will try to infer a primary key from dbt’s uniqueness tests. If you have a single column uniqueness test defined, it will use this column as the PK.unique_key config of incremental models and snapshots, then columns named id, pk, pkey, or <model_name>_id.