简体   繁体   English

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

[英]SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

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. 我在我的Web项目中使用cakePHP框架,似乎很多人以前已经问过类似的问题。即使我尝试了找不到的答案。

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. 您似乎将dd添加到disease_id列。 Which has a constraint. 哪个有约束。 Most often ID columns are numerical. ID列通常是数字列。 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). 将最有可能被允许(我不知道ID 1是什么疾病,但这又是另一个问题)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails Laravel:SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键约束失败 - Laravel: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:Laravel 5中的外键约束失败 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails in Laravel 5 SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails SQLSTATE [23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败 - Laravel - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails - Laravel SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键约束失败 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails Laravel-SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键约束失败 - Laravel - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails Laravel 6 - SQLSTATE[23000]:违反完整性约束:1452 无法添加或更新子行:外键约束失败 - Laravel 6 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails Laravel 6 - SQLSTATE[23000]:违反完整性约束:1452 无法添加或更新子行:外键约束失败 - Laravel 6 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM