Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CDbCommand无法执行SQLSTATE[23000]_Php_Mysql_Yii - Fatal编程技术网

Php CDbCommand无法执行SQLSTATE[23000]

Php CDbCommand无法执行SQLSTATE[23000],php,mysql,yii,Php,Mysql,Yii,我正在尝试创建用户,但每次单击创建时,都会出现以下错误: 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 (`dcpcommunity`.`system_users`, CONSTRAINT `syst

我正在尝试创建用户,但每次单击创建时,都会出现以下错误:

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 (`dcpcommunity`.`system_users`, CONSTRAINT `system_users_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`)). The SQL statement executed was: INSERT INTO `system_users` (`status`, `date_modified`, `username`, `password`, `date_last_login`, `date_created`, `user_role`, `isLogin`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7)
我读到这个错误意味着我的表中没有“party_id”,但我进行了三次检查,party_id作为我的system_users表的主键存在

我还看到它显示了REFERENCES
parties
,我在模型中检查了REFERENCES部分,并将其更改为我的表名,但仍然出现此错误

public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'party' => array(self::BELONGS_TO, 'system_users', 'party_id'),
    );
}
编辑

[system_users]
pk: party_id
username
password
date_last_login
status
date_created
date_modified
user_role
isLogin
有一个Parties表,其中包含字段id和party\u type\u id

编辑

[system_users]
pk: party_id
username
password
date_last_login
status
date_created
date_modified
user_role
isLogin
我检查了我的数据库,在我的system_users表中,我发现party_id与:

db.parties.id


创建新记录时,如何使这种关系成为可能?

因为sql错误声明:引用方id。。。各方是db中的一个表。AR将根据关系函数的状态,寻找一个称为Party的AR模型。 在AR模型中,“当事方”应该是一个使用“当事方”表的定义。 错误来自数据库(模式)的错误。
“创建”操作试图插入一个与system_users或parties中的架构定义不对应的值。

能否向我们展示您的party和system users架构的架构?是否有方法使其链接到我希望插入的表?我是通过Gii生成这些模型的,所以我不确定它为什么链接到错误的表。你说的“链接到表”是什么意思?我的意思是将模型从控制器传递到视图(创建)。你必须扩展创建操作