February 17, 201115 yr HI I have a problem with Foriegn Keys, ive been trying to work it out now for over a week. Ive watched Tutorials after Tutorials, copied what they have said but its not working. And its only a simple Database with 2 Tables which require a FK join. I have 2 tables as shown below: CustomerData (parent table) ID Name Address Email PhoneNumber MobileNumber Country City Password PetData (child table) CustomerID --foreign key linked to ID form parent table Type Breed Age Colour Price SalesPoint Description Image1 Image2 But i just cannot get it to work i keep getting this error: Cannot add or update a child row: a foreign key constraint fails (`petseen`.`petdata`, CONSTRAINT `petdata_ibfk_1` FOREIGN KEY (`CustomerID`) REFERENCES `customerdata` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE) I need the customer to be able to upload as many pet ads as they wish. any help would be great and many thanks.
February 17, 201115 yr Just to double-check - you ARE updating CustomerData first, right? What's the query? Edited February 17, 201115 yr by Renaissance-Design
February 17, 201115 yr You're probably supplying petData with a CustomerID which doesn't exist in CustomerData.
February 18, 201115 yr Have you already got data in the petdata table which may contradict the constraint? That's usually where the issue lies if everything else looks ok! Keith
Create an account or sign in to comment