Closed julmaxi closed 8 months ago
Ping for @julmaxi I tested your code, and It fixed this and https://github.com/SeaQL/sea-orm/issues/1690 Please send your code as pull request. If you don't do it, I'll submit a pull request on behalf of you.
Thanks for testing. I will create a pull request.
@julmaxi May I send this as pull request?
I've run into a semi-related issue where I still couldn't get the code to generate correctly in a composite foreign key but the problem was that I had a foreign key that referenced something that has a unique index but not a unique constraint, also see this: https://stackoverflow.com/questions/61249732/null-values-for-referential-constraints-unique-constraint-columns-in-informati
The fix was to run code like this:
ALTER TABLE table_name
ADD CONSTRAINT constraint_name UNIQUE USING INDEX index_name;
And then the constraint is correctly referenced in the information_schema
Description
Postgres schema discovery produces incorrect results for composite foreign keys. Specifically, for a key with $n$ columns each key is repeated $n$ times in both
columns
andforeign_columns
.Steps to Reproduce
On a Postgres database:
Create a schema with a composite primary key and a corresponding foreign key. The following is a minimal example:
CREATE TABLE Child ( id INT PRIMARY KEY, parent_id1 INT, parent_id2 INT,
);
References { name: "child_parent_id1_parent_id2_fkey", columns: [ "parent_id1", "parent_id2", ], table: "parent", foreign_columns: [ "id1", "id2", ], on_update: Some( NoAction, ), on_delete: Some( NoAction, ), }
References { name: "child_parent_id1_parent_id2_fkey", columns: [ "parent_id1", "parent_id1", "parent_id2", "parent_id2", ], table: "parent", foreign_columns: [ "id1", "id2", "id1", "id2", ], on_update: Some( NoAction, ), on_delete: Some( NoAction, ), }
However, I am not sure if I overlook any side effects of this fix.