我試圖創建一個用戶,但每次點擊創建,我得到這個錯誤: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
如何在創建新記錄時使這種關係成爲可能?
您能向我們展示您的派對和系統用戶架構的方案嗎? –