I am using cakePHP framework in my web project,It seems many people have already ask similar question before.Even I try for those I couldn't find the answer.
Here is the error I got'
Database Error
Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`fit_or_fat`.`disease_suggestions`, CONSTRAINT `disease_suggestions_ibfk_1` FOREIGN KEY (`disease_id`) REFERENCES `diseases` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
SQL Query: INSERT INTO `fit_or_fat`.`disease_suggestions` (`title`, `suggestion`, `disease_id`, `modified`, `created`) VALUES ('cholestorol', 'dddddddddddddddd', 'dd', '2014-08-24 00:04:32', '2014-08-24 00:04:32')
This is my model
'disease_id' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'disease_id must not be empty',
),
'custom' => array(
'rule' => '/[\w\s\d., \-_]+/',
'message' => 'user_id can only contain simple and capital letters, 0-9 numbers, . , - _ space and tabs only.',
),
),
You appear to be adding dd
to the disease_id column. Which has a constraint. Most often ID columns are numerical. So this warning is telling you the the query is wrong, or specifically trying to insert values not allowed.
INSERT INTO `fit_or_fat`.`disease_suggestions` (`title`, `suggestion`, `disease_id`, `modified`, `created`) VALUES ('cholestorol', 'dddddddddddddddd', 1, '2014-08-24 00:04:32', '2014-08-24 00:04:32')
Will most likely be allowed (I have no idea what disease is on ID 1 but that's another issue all together).