gezzeg
(Mr Ghazali)
April 11, 2012, 3:53pm
1
Hi,
I got this error,
CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`test13`.`tbl_membership`, CONSTRAINT `id` FOREIGN KEY (`user_id`) REFERENCES `tbl_user` (`username`) ON DELETE NO ACTION ON UPDATE NO ACTION). The SQL statement executed was: INSERT INTO `tbl_membership` (`membership_id`, `membership_date`, `membership_status`, `membership_expired`, `membership_type`, `user_id`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5)
i would like to know how to change REFERENCES tbl_user
(username
) to id. Where should i do it?
abennouna
(Abennouna)
April 11, 2012, 6:25pm
2
Hi, I guess that you can use phpMyAdmin (for instance) and edit the FK between your tables? Well there should be some ALTER command, but I haven’t done that on FKs. phpMyAdmin is generally user-friendly.
Sorry if it’s not helping
gezzeg
(Mr Ghazali)
April 12, 2012, 5:01am
3
Hi, I guess that you can use phpMyAdmin (for instance) and edit the FK between your tables? Well there should be some ALTER command, but I haven’t done that on FKs. phpMyAdmin is generally user-friendly.
Sorry if it’s not helping
Hi! Thanks for your helps! It seems like my FK is worng but actually i have set it properly.
I found out that its relate to Not Null issues.
I drop and recreate the tables back with all columns Not Null.
Its solve my problems. Thanks bennouna!