I’m trying to set constraints for a contract in my models.yml file and I am getting build errors when I set the expression to a text value like "ref(‘dim_customers’) (CustomerKey). The specific error I am getting is “no parent table defined”.
I’m trying to do this so that I can have primary and foreign keys assigned to my tables to help with data discovery during power bi connections.
I’ve tried variations of the expression like <model_schema>.<model_table> (<model_column>) as it is shown in the documentation but it still doesn’t work and I get the no parent table defined error.
My yaml file:
- name: partner_customer_bridge
description: A bridge table that relates customers to partners.
config:
contract:
enforced: true
tests:
- dbt_expectations.expect_table_columns_to_match_ordered_list:
column_list: ["PartnerKey", "CustomerKey"]
columns:
- name: PartnerKey
description: The primary key from the partner dimension.
data_type: string
constraints:
- type: not_null
- type: foreign_key
expression: "ref('dim_partners') (PartnerKey)"
tests:
- not_null
- relationships:
to: ref('dim_partners')
field: PartnerKey
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: string
- name: CustomerKey
description: The primary key from the customer dimension.
data_type: string
constraints:
- type: not_null
- type: foreign_key
expression: "ref('dim_customers') (CustomerKey)"
tests:
- not_null
- relationships:
to: ref('dim_customers')
field: CustomerKey
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: string
The exact error message I am getting when I attempt to build:
No parent table defined for foreign key: