Thread: Foreign Key Issues
04-04-13, 18:29 #1Registered User
- Join Date
- Apr 2013
Unanswered: Foreign Key Issues
Hello, I am using phpmyadmin on xampp and I have created a database for a project I am doing but with no data yet. I've assigned the primary keys and from what I believe I have also set up the foreign key relationships. Now i am trying to add the data but I am getting the following error.
"SQL query: Edit
INSERT INTO `happy homes`.`development` (
'12', '123', '12343', 'sdsdfgdfg'
MySQL said: Documentation
#1452 - Cannot add or update a child row: a foreign key constraint fails (`happy homes`.`development`, CONSTRAINT `development_ibfk_3` FOREIGN KEY (`regional_id`) REFERENCES `development` (`regional_id`)) "
-- I can't make sense of the error really as I am a beginner with SQL. Could someone please help me with this issue?
04-04-13, 18:56 #2Resident Curmudgeon
Provided Answers: 54
- Join Date
- Feb 2004
- In front of the computer
You've created a foreign key that refers to itself. This creates a requirement for data that is impossible to fulfill.
You need to drop the existing incorrect development_ibfk_3 constraint and then recreate it so that it references another (correct) table.
I'm going to hazard a guess that the correct table name for this constraint is probably `region`.
I'd also like to suggest that you change your table names from singular (such as development) to plural (such as developments).
-PatPIn theory, theory and practice are identical. In practice, theory and practice are unrelated.