Yii Framework Forum: A Foreign Key Constraint Fails - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

A Foreign Key Constraint Fails

#1 User is offline   cr1ng3r 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-October 12

Posted 10 October 2012 - 06:05 AM

Currently on page 120, but I cannot seem to run the query to manually assign the two users to Project 1. Everytime I run it I get an error that states:
#1452 - Cannot add or update a child row: a foreign key constraint fails (`trackstar_dev`.`tbl_project_user_assignment`, CONSTRAINT `FK_project_user` FOREIGN KEY (`project_id`) REFERENCES `tbl_project` (`id`) ON DELETE CASCADE)


I'm not entirely sure why this is failing as I set the foreign keys according to what the book said.
ALTER TABLE tbl_project_user_assignment
ADD CONSTRAINT FK_project_user FOREIGN KEY
(project_id)
REFERENCES tbl_project(id)
ON DELETE CASCADE
ON UPDATE RESTRICT
;

ALTER TABLE tbl_project_user_assignment
ADD CONSTRAINT FK_user_project FOREIGN KEY
(user_id)
REFERENCES tbl_user(id)
ON DELETE CASCADE
ON UPDATE RESTRICT
;


Any help in resolving this issue would be greatly appreciated.
0

#2 User is offline   cr1ng3r 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-October 12

Posted 10 October 2012 - 09:19 AM

I ended up figuring it out. It appears that I did not have any projects created, so the query was failing. Once I created a couple projects everything worked correctly.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users