首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"CDbCommand未能执行SQL语句: SQLSTATE[23000]:“图书中的示例

"CDbCommand未能执行SQL语句: SQLSTATE[23000]:“图书中的示例
EN

Stack Overflow用户
提问于 2013-08-16 13:03:05
回答 1查看 3.6K关注 0票数 0

日安!面对这样的问题,当创建问题(http://test.com/book/ima/index.php?ssue/create&pid=1)时得到以下错误:

代码语言:javascript
复制
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`trackstar`.`tbl_issue`, CONSTRAINT `fk_issue_owner` FOREIGN KEY (`owner_id`) REFERENCES `tbl_user` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `tbl_issue` (`project_id`, `name`, `description`, `type_id`, `status_id`, `owner_id`, `requester_id`, `create_time`, `create_user_id`, `update_time`, `update_user_id`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7, :yp8, :yp9, :yp10)

/var/www/yii/framework/db/CDbCommand.php(357)

345         {
...

我试过这样做:http://www.yiiframework.com/forum/index.php/topic/11953-cdbcommand-failed-to-execute-the-sql-statement-sqlstate23000-integrity-constraint-violation/

代码语言:javascript
复制
 public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('name, project_id', 'required'),
        .....
        ........
    );
}

它不起作用。帮助解决问题,我想进一步学习,但因为它,我不能。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-16 13:35:42

从您给出的链接和错误中,可能是由于以下原因造成了约束违规:

代码语言:javascript
复制
The user_id attempting to be inserted is not associated with a valid tbl_user.id value in the tbl_user table.

错误信息是如此明显。您尝试在tbl_issue中插入一个包含外键user_id的记录,该记录在tbl_user上不存在。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18273993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档