Scenario:
Parent table | id primary key, message_p
Child table | id primary key, parent_id foreign key, message_c
I had 1 row of data in the parent table and 2 rows of data in the child table. I wanted to test constraints that an FK relationship enforces. I then attempted to remove the foreign key from the child table so that evene though the child table had 2 rows, I could then go ahead and remove the parent row:
alter table child
drop foreign key parent_id
I then got the following error:
[1091 - Can't DROP 'parent_id'; check that column/key exists]
Notes:
show create table child
CREATE TABLE `track` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`member_id` int(11) NOT NULL,
`title` varchar(50) DEFAULT NULL,
`artist` varchar(50) DEFAULT 'TBA',
`album` varchar(50) DEFAULT 'TBA',
`genre` varchar(50) DEFAULT 'TBA',
`dance_style` varchar(50) DEFAULT 'TBA',
PRIMARY KEY (`id`),
KEY `member_id` (`member_id`),
CONSTRAINT `track_ibfk_1` FOREIGN KEY (`member_id`) REFERENCES `member` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Am I missing something in my query or the general understanding about FK's?
You are trying to delete the Foreign Key Constraint by column name, that's why your code doesn't work.
First query your foreign key constraint name (using
show create table child
as you did show the key name, something liketrack_ibfk_1