-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreign key not detected in tables object #1643
Comments
I can solve this issue. Please assign this bug to me. |
@Bidhu1024 can u please update if not can i work on this @mathiasrw |
can i have the documentation for it @mathiasrw |
SELECT
ccu.table_name AS table_name,
ccu.column_name AS column_name,
ccu.constraint_name AS constraint_name,
ccu.referenced_table_name AS referenced_table_name,
ccu.referenced_column_name AS referenced_column_name
FROM
information_schema.key_column_usage AS kcu
JOIN
information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = kcu.constraint_name
WHERE
kcu.constraint_schema = 'your_schema'
AND ccu.table_name = 'Table2'
AND ccu.column_name = 'Column1'; @mathiasrw try this it will retrieve the information regarding the foreign keys |
@mathiasrw could u try this |
Looks correct to me. @matndev Does this work? |
@matndev can u update? |
@matndev any updates |
Tried today, returns me undefined when executing SELECT in console.log.
|
@DarrenDsouza7273 do you know a different way to retrieve the foreign keys from a table? I tried your solution and I got the same error as @matndev. Such as they mentioned, I would also prefer to retrieve this information from the tables object, and I'm up to make a PR for it even 🙂 |
I'm having an issue with foreign key detection. I'm creating two tables, let's call them "Table1" and "Table2". Table1 has a primary key called "PK_Table1" on a column named "Column1". Table2 has a foreign key "FK_Table2_Column1" that references "Column1" in "Table1".
When I create the tables and inspect the resulting objects, "Table1" correctly shows "Column1" as having a primary key, but "Table2" does not show "Column1" as having a foreign key. Additionally, when I try to access the "foreignkey" property of "Column1" in "Table2", it doesn't exist.
I've checked the "checks" property of "Table2", and the foreign key constraint appears to be correctly detected and stored there (fk is equal to true and the name of the foreign key is printed, but not the columnid).
Could you please advise on how to properly detect and access foreign keys?
JSFiddle: https://jsfiddle.net/rcnv6gfs/
The text was updated successfully, but these errors were encountered: