Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013
    Posts
    4

    Unhappy 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` (
    `development_id` ,
    `regional_id` ,
    `employee_id` ,
    `location`
    )
    VALUES (
    '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?

    Thanks!

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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).

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •