The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

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

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

0
Votes
1
Answer

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

1 Answer

365 Team
0
Votes

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

×
LAST CHANCE
Ready to Learn Data Science?
50% OFF