0

I am using yii poll extension. I copied the sql file into my db. It works fine untill i vote. But when i click on vote it shows command error. ie:- 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 (database.poll_vote, CONSTRAINT vote_user FOREIGN KEY (user_id) REFERENCES users (uid) ON DELETE CASCADE ON UPDATE CASCADE). The SQL statement executed was: INSERT INTO poll_vote (user_id, ip_address, timestamp, choice_id, poll_id) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4);

I havent implemented this part of document. 1. Setup a User active record with an integer ID returned by Yii::app()->user->id.*

Can anyone help wt does that mean.

I do have users table with uid column in same database. some how im not able to get the point. And how can i avoid the constraint failure. Im sorry im new to yii.. Any help will be appreciated. Thank you.

4

1 回答 1

0

它失败了,因为正如您所说,您跳过了“使用 Yii::app()->user->id.* 返回的整数 ID 设置用户活动记录”

“完整性约束违规”是说外键约束失败,并继续说外键是你说你从未创建过的 user_id。

看起来扩展程序正在跟踪谁使用 user_id 进行了投票,并且由于您尚未创建 ID,因此您会收到错误消息。

有关如何修改 Y ii:app()->user 的信息,请参阅此页面

于 2012-07-19T16:14:38.807 回答