Closed PtrckGdwn closed 2 months ago
Will need to investigate why this isn't working...looking at the macro def, it looks as though it should. Do you mind sharing the dbt.log with me via email? ben.cassell@databricks.com
Ah, found the issue. Thanks for reporting.
@PtrckGdwn are there any earlier versions where this does work? I'm trying to narrow down whether a.) this never worked or b.) it used to work but dbt Labs changed how constraint config is validated.
@benc-db I don't know if there are any earlier versions that worked. I suspect the issue may be due to the introduction of some support for a similar method of adding fk constraints that was added to dbt core recently (though apparently will not be operational until v1.9 - see: https://github.com/dbt-labs/dbt-core/issues/8062#issuecomment-2316231542).
One thing to note though about the dbt core change is that I believe it will add support for ref('my_model') against the the 'to' attribute. This would be a awesome thing to have flow through to dbt-databricks, because at present FKs are not part of the dag and you need to use explicit depends_on statements in models to ensure they build in the correct order.
Describe the bug
When trying to create a foreign key constraint on a relation using the
parent
andparent_columns
constraint attributes, I am getting an error at run time:No parent table defined for foreign key
which is followed by a trace.Steps To Reproduce
I have configured the model's schema like so:
When running the project this results in the error message described above.
Expected behavior
The foreign key sql should be generated, and assume all else is good (e.g., the parent_table has a primary key) the foreign key should be created.
Screenshots and log output
If applicable, add screenshots or log output to help explain your problem.
System information
The output of
dbt --version
:The operating system you're using: Running as a dbt task in a Databricks workflow. Compute: Single node: Standard_DS3_v2 · DBR: 14.3.x-photon-scala2.12
Additional context
The traditional
expression
method of creating a foreign key works as documented, but I would like to avoid using it because it has a hard coded schema name. Theparent
+parent_columns
method assumes that the parent table is in the same schema as the child, which for me is true.