Cannot Add or Update a Child row: A foreign constraint fails
Sorry to keep bothering everyone, but my databse just doent seem to be happy?? I keep getting the above error in my database when my parent table is empty. I am using visual basic to talk to it. Wehener I try and add a new row, on the update function it throws up the above error. However my program manages to add data to the Questionnaire_title table, but when it moves on to adding data to my questions table it throws a wobbly. Can anyone tell me why??
SYNTAX:
CREATE TABLE questionnaire_title ( Survey_ID int(10) unsigned zerofill NOT NULL auto_increment, User_ID int(11) NOT NULL default '0', Date varchar(100) NOT NULL default '', title varchar(100) NOT NULL default '', Archive varchar(100) NOT NULL default '',
PRIMARY KEY (Survey_ID) ) ENGINE=INNODB;
CREATE TABLE questions ( Question_id int(10) unsigned zerofill NOT NULL auto_increment, Survey_ID int(11)unsigned NOT NULL default '0', Question varchar(100) NOT NULL default '', data_option varchar(100) NOT NULL default '',
PRIMARY KEY (Question_id), INDEX ( Survey_ID), FOREIGN KEY (Survey_ID) REFERENCES questionnaire_title(Survey_ID) ON DELETE CASCADE ) ENGINE=INNODB;
Solution: Cannot Add or Update a Child row: A foreign constraint fails
I don't know VB code very well, but you do need to create another SELECT statement right after the INSERT into the questionnaire_title table and read the result into a variable: