Last answered:

14 Mar 2022

Posted on:

31 Aug 2020

1

Foreign key Error: Unhandled exception: invalid column contraint_name for resultset

Hi,
When I apply the Foreign Key code or through the Alter Table button to give a custom name, I can see that it shows the Foreign Key on the DDL tab. However, in both cases, I see that the Foreign Keys tab is empty. When I click on Refresh, it shows the following error:
Foreign key Error: Unhandled exception: invalid column
contraint_name for resultset
.
This is what the DDL shows when doing it through code:
CREATE TABLE `sales` (
`purchase_number` int NOT NULL AUTO_INCREMENT,
`date_of_purchase` date DEFAULT NULL,
`customer_id` int DEFAULT NULL,
`item_code` varchar(10) DEFAULT NULL,
PRIMARY KEY (`purchase_number`),
KEY `customer_id` (`customer_id`),
CONSTRAINT `sales_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

.

This is what the DDL shows when doing it through the Alter Table button
CREATE TABLE `sales` (
`purchase_number` int NOT NULL AUTO_INCREMENT,
`date_of_purchase` date DEFAULT NULL,
`customer_id` int DEFAULT NULL,
`item_code` varchar(10) DEFAULT NULL,
PRIMARY KEY (`purchase_number`),
KEY `Constraint_1` (`customer_id`),
CONSTRAINT `Constraint_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Thank you for your help

6 answers ( 0 marked as helpful)
Instructor
Posted on:

03 Sept 2020

0

Hi Harold!
Thanks for reaching out.

Generally, you may have created the foreign key on a wrong column. You can try removing it and then creating it again.
If this doesn't help, I am afraid the issue may be related to the version of Workbench you are using.

But in this case, it seems to me that it says KEY as opposed to FOREIGN KEY. Also, the constraint has been created in both cases (and the given names are automatic, so they shouldn't be regarded as an issue).inall

Finally, do you obtain an error in both cases?

Supporting your question with screenshots may help us assist you better. Thank you.

Hope this helps.
Best,
Martin

Posted on:

26 Oct 2021

1

This is a bug https://bugs.mysql.com/bug.php?id=101484

I did not find if Oracle has fixed it.

Instructor
Posted on:

01 Nov 2021

0

Hi Mohamed!

Thanks for reaching out.

Please be aware that while sometimes Oracle quickly respond to their bugs, other times they do not solve them for quite a while.
Nevertheless, please bear in mind that according to our observations, the bugs we encounter in Workbench while completing the course are only temporary. Usually, restarting the software and/or the connection solves the issue and allows us to continue with the next lectures from the course.

Hope this helps.
Best,
Martin

Posted on:

04 Mar 2022

0

Salaam Mohamed, I'm facing the exact same bug and getting the same error.
Foreign keys aren't showing in the foreign keys tab after manually adding setting up a foreign key by altering the table through the GUI.

Posted on:

04 Mar 2022

0

I tried restarting the software (ie. workbench) and reconnecting but to no avail. Ignoring it for now and moving on to the next section. Will try it again the next time I restart my computer. Just have a lot of applications that I can't switch off right now.

Instructor
Posted on:

14 Mar 2022

0

Hi E E!
Thanks for reaching out.

This is a frequently encountered bug from the Workbench. Nevertheless, this will not hamper the smooth taking of the course.

Hope this helps.
Best,
Tsvetelin

Submit an answer