I have had a 1 to many relationship between course and instructor, which I wanted to drop. When I tried to drop the instructorID in course table it told me that. I couldn't drop it as it was a foreign key. Then I decided to drop it like this:
ALTER TABLE course DROP FOREIGN KEY instructorID
But i get this error :
#1091 - Can't DROP 'InstructorID'; check that column/key exists
I don't get what this error means. what am i doing wrong?
Dropping Foreign Key Constraints You can drop a foreign key constraint using the following ALTER TABLE syntax: ALTER TABLE tbl_name DROP FOREIGN KEY fk_symbol; If the FOREIGN KEY clause defined a CONSTRAINT name when you created the constraint, you can refer to that name to drop the foreign key constraint.
To drop a foreign key, right-click the row you wish to delete, then select the Delete Selected FKs menu item. To modify properties of a foreign key, select it and make the desired changes.
In "Structure" tab, click on "see relational view" below the fields. Here you can remove the foreign keys by selecting an empty value in the dropdown.
Please run an SHOW CREATE TABLE course;
to make sure instructorID is the name of foreign key constraint.
Additional: The error means MySQL searches for a foreign key constraint named "InstructorID" but there is no constraint with such name, maybe this is your column name, but you have to use the constraint name to delete foreign keys.
After you run SHOW CREATE table course;
you should find the fk symbol which is commonly like the one bellow:
(course_ibfk_1)
it may differ according to your mysql version you are using then drop the foreign key using the fk symbol as follow :
alter table course drop foreign key course_ibfk_1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With