Error 1452
Hi,
I'm using MySQL Query Browser and I have two tables:
Candidate and Poll
CREATE TABLE `elections`.`poll` (
`id` int(10) unsigned NOT NULL auto_increment,
`pollname` varchar(45) NOT NULL,
`election_fk` int(10) unsigned NOT NULL,
`polldate` datetime NOT NULL,
`pollplace` varchar(45) NOT NULL,
`pollstatus` varchar(45) NOT NULL,
PRIMARY KEY USING BTREE (`id`),
CONSTRAINT `election_fk` FOREIGN KEY (`id`) REFERENCES `election` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
CREATE TABLE `elections`.`candidate` (
`id` int(10) unsigned NOT NULL auto_increment,
`candidatename` varchar(45) NOT NULL,
`poll_fk` int(10) unsigned NOT NULL,
PRIMARY KEY USING BTREE (`id`,`poll_fk`),
CONSTRAINT `poll_fk` FOREIGN KEY (`id`) REFERENCES `poll` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
I have two rows in my Poll table one with ID, 1 and the other 2.
I tried the following:
insert into Candidate values(1, 'name', 1);
insert into Candidate values(2, 'name', 1);
insert into Candidate values(3, 'name', 2);
The first two succeeded but on the last one I recieve the following error:
Cannot add or update a child row: a foreign key constraint fails (`elections/candidate`, CONSTRAINT `poll_fk` FOREIGN KEY (`id`) REFERENCES `poll` (`id`))
The same thing happened when trying to insert rows in the Poll table, which has a foreign key to Elections table. After two successfull insertion it stopped working with the same error.
Is this a bug that I cannot add more than two rows? or is it because of something else?