我试图创建一个用户,但每次点击创建,我得到这个错误:CDbCommand执行失败SQLSTATE [23000]
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
,我检查了我的模型的引用部分,并将其更改为我的表名,我仍然得到这个错误。
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
没有与域ID的缔约方表和party_type_id
编辑
我检查我的数据库,并在我的system_users表,我发现该party_id与以下关系有关:
db.parties.id
如何在创建新记录时使这种关系成为可能?
您能向我们展示您的派对和系统用户架构的方案吗? –