dimanche 21 décembre 2014

Problem in adding foreign key


I'm having an error while adding a foreign key constrain to my database.


In my database, I'm having a table named user, student, staff, complaint and review.


The table user contains fields such as UserID (Primary), Name, etc.


Student contains RegNo (Primary), Year, etc.


Staff contains StaffID (Primary), Year, etc.


Complaint contains CompID (Primary), Desc, AssignedTo, RegNo, etc.


Review contains RevID (Primary), CompID, StaffID, etc.


So, I successfully created the relationship between Student.RegNo and User.UserID, Complaint.RegNo and Student.RegNo, Staff.StaffID and Complaint.AssignedTo & Review.StaffID and Staff.StaffID.


But whenever I'm trying to create a relation between Staff.StaffID and User.UserID (StaffID as Primary and UserID as foreign), I'm getting and error



#1452 - Cannot add or update a child row: a foreign key constraint fails (cms.#sql-570_e3, CONSTRAINT StaffID FOREIGN KEY (StaffID) REFERENCES user (UserID))






Aucun commentaire:

Enregistrer un commentaire