databricks / dbt-databricks

A dbt adapter for Databricks.
https://databricks.com
Apache License 2.0
226 stars 119 forks source link

Issue 747 primary key autoname #774

Closed elca-anh closed 3 months ago

elca-anh commented 3 months ago

Resolves #747

Description

Checklist

benc-db commented 3 months ago

Thanks for opening, will run the test suite to see where we stand.

PtrckGdwn commented 2 months ago

Hi, I am really keen to use the non-expression method for foreign keys. Unfortunately, when I try it, I get an error message like: "No parent table defined for foreign key: " followed by a trace.

I have configured the schema for the model like so:

  - name: example__child_table
    constraints:
      - type: primary_key
        name: pk_example__child_table
        columns: ["id"]
      - type: not_null
        columns: ["id", "name", "parent_id"]
      - type: foreign_key
        name: fk_example__child_table_1
        columns: ["parent_id"]
        parent: parent_table
        parent_columns: ["id"]
    columns:
      - name: id
      - name: name
      - name: parent_id

Any tips on how to get this working? I've had a look at the macro code, and it appears the constraint.get("parent") call is not returning anything, hence the error message, but I can't see anything obvious I am doing wrong.

Running with adaptor version 1.8.5