I have these tables:
CREATE TABLE `faculty_personal_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Designation` varchar(30) NOT NULL,
`First_Name` varchar(20) NOT NULL,
`Middle_Name` varchar(20) DEFAULT NULL,
`Last_Name` varchar(20) NOT NULL,
`Date_of_Birth` date NOT NULL,
`Address` varchar(100) NOT NULL,
`City` varchar(30) NOT NULL,
`Pincode` int(11) NOT NULL,
`Email` varchar(40) NOT NULL,
`Contact_Number` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
CREATE TABLE `faculty_edu_qual` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`faculty_id` int(11) NOT NULL,
`Degree` varchar(15) NOT NULL,
`Specialisation` varchar(40) NOT NULL,
`University` varchar(40) NOT NULL,
`Grade` varchar(10) NOT NULL,
`Year_of_Passing` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
KEY `FK_faculty_edu_qual_faculty_personal_info` (`faculty_id`),
CONSTRAINT `FK_faculty_edu_qual_faculty_personal_info` FOREIGN KEY (`faculty_id`) REFERENCES `faculty_personal_info` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
I have inserted a record in the faculty personal info table successfully. Now when I use this commands,
set @faculty_id = last_insert_id();
insert into faculty_equ_qual values('1',@faculty_id,'B.Tech','CSE','PEC','S','2015');
I get this error:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`faculty_student`.`faculty_edu_qual`, CONSTRAINT `FK_faculty_edu_qual_facu
lty_personal_info` FOREIGN KEY (`faculty_id`) REFERENCES `faculty_personal_info`
(`id`) ON DELETE CASCADE ON UPDATE CA)