By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

cannot add or update a child row

P: 2
Please help,I'm very frustated.

when I ADD
the data in kn_history_question table of htbase_tst database....it giving the error "Cannot add or update a child row:a foreign key constraint fails,<'htbase_tst/kn_history_question', CONSTRAINT 'FK_kn_history_question_complaint' FOREIGN KEY ('complaint_id' ) REFERENCES 'complaint'('id')).

This is my table script.....

CREATE TABLE `city` (
`id` int(11) NOT NULL auto_increment,
`city_name` varchar(255) default NULL,
`city_code` varchar(80) default NULL,
`state_id` int(11) default NULL,
`Nearest_airport_code` varchar(80) default NULL,
`date_updated` timestamp NULL default NULL,
`date_created` timestamp NULL default NULL,
PRIMARY KEY (`id`),
KEY `FK_cities_states` (`state_id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;


CREATE TABLE `kn_history_question` (
`id` int(11) NOT NULL auto_increment,
`complaint_id` int(11) default NULL,
`question_text` varchar(255) default NULL,
`sex_relevance` varchar(20) default NULL,
`age_group_relevance` varchar(255) default NULL,
`date_created` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`date_updated` timestamp NOT NULL default '0000-00-00 00:00:00',
`count_of_responses` int(5) default NULL COMMENT ', paint radio buttons if value is one else check boxes',
`doctor_id` int(11) default NULL,
PRIMARY KEY (`id`),
KEY `FK_kn_history_question_complaint` (`complaint_id`),
CONSTRAINT `FK_kn_history_question_complaint` FOREIGN KEY (`complaint_id`) REFERENCES `complaint` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


ERROR:"Cannot add or update a child row:a foreign key constraint fails,<'htbase_tst/kn_history_question', CONSTRAINT 'FK_kn_history_question_complaint' FOREIGN KEY ('complaint_id' ) REFERENCES 'complaint'('id')).

Please give the solution of this ERROR.
Jul 8 '07 #1
Share this Question
Share on Google+
1 Reply


dafodil
100+
P: 392
Some row in the child does not comply with the constraint, correct the problem.
You find the rows like this:
select child.id from child left join parent on (child.parent_id=parent.id) where child.id is not null and parent.id is null;
Jul 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.