2014-08-23 10:23
浏览 346

SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败

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.',

图片转代码服务由CSDN问答提供 功能建议

我在我的web项目中使用cakePHP框架,似乎很多人之前已经问过类似的问题。即使我试过 对于那些我找不到答案的人。


数据库错误 < pre> 错误:SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败(`fit_or_fat` .disease_suggestions`,CONSTRAINT`seise_suggestions_ibfk_1` FOREIGN KEY(`disease_id`) 引用`疾病`(`id`)ON DELETE CASCADE ON UPDATE CASCADE) SQL查询:INSERT INTO`fit_or_fat``disease_suggestions`(`title`,`suggestion`,`disease_id`,`modified`,`创建 `)VALUES('cholestorol','dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'dd pre>


 'disease_id'=&gt; 数组(
' 自定义'=&gt;数组(
'规则'=&gt;'/ [\ w \ s \ d。,\ _-] + /',
'消息'=&gt;'user_id只能包含简单和资本 字母,0-9数字,。, -  _空格和制表符。',
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • doujiang5211 2014-08-23 10:32

    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).

    解决 无用
    打赏 举报

相关推荐 更多相似问题