Mysql Using Navicat (error --- Foreign Key Fails)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Harshpandya
    New Member
    • Jun 2007
    • 30

    Mysql Using Navicat (error --- Foreign Key Fails)

    Hi I am new at ASP and MYSQL.

    I am Using Navicat to access MYSQL database.

    My Problem is when i create the foreign key in "Navicat" -it gives me this error.

    1452-cannot add or update child row: a foreign key constraint fails....

    Can any body help me - why am i getting this error - and how to fix it --

    Is anything wrong --- I am trying since 2 days - no one knows how to fix it ?

    Thanks,
    Harsh (INDIA)
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Harshpandya
    Hi I am new at ASP and MYSQL.

    I am Using Navicat to access MYSQL database.

    My Problem is when i create the foreign key in "Navicat" -it gives me this error.

    1452-cannot add or update child row: a foreign key constraint fails....

    Can any body help me - why am i getting this error - and how to fix it --

    Is anything wrong --- I am trying since 2 days - no one knows how to fix it ?

    Thanks,
    Harsh (INDIA)
    Apparently a foreign key constraint has failed. You can use

    [CODE=sql]show innodb status; [/CODE]

    to show the last foreign key constraint that failed.

    Comment

    • Harshpandya
      New Member
      • Jun 2007
      • 30

      #3
      Originally posted by r035198x
      Apparently a foreign key constraint has failed. You can use

      [CODE=sql]show innodb status; [/CODE]

      to show the last foreign key constraint that failed.
      I am sorry but i did not get it. I am using Navicat that is only GUI no code section.

      Details: I want to do relationships with two tables. Players and Manufacturers

      To do that in VWD. i have to assign the index key and foreign key in Navicat.

      When i put the Index key it works but when i assign foreign key -- it ask me to put the reference table and choose the columns i want.

      I choose - what i want and when i click ok i get this error that

      Foreign Key constraint Fails:------


      Thanks in advance,
      Harsh

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Harshpandya
        I am sorry but i did not get it. I am using Navicat that is only GUI no code section.

        Details: I want to do relationships with two tables. Players and Manufacturers

        To do that in VWD. i have to assign the index key and foreign key in Navicat.

        When i put the Index key it works but when i assign foreign key -- it ask me to put the reference table and choose the columns i want.

        I choose - what i want and when i click ok i get this error that

        Foreign Key constraint Fails:------


        Thanks in advance,
        Harsh
        Well you have to understand your tables and the constraints that exist on them. Something is happening to a foreign key which is not allowed by one of your constraints. Check against your constratints.

        Comment

        • cheerpeter13
          New Member
          • Sep 2009
          • 1

          #5
          i meet the same error. I found my mistake is I inserted data, which not corresponding to both table before I create foreign key.

          Ex: table a(id, name) with 2 record (1,peter); (2, flower)
          table b(id, sex) with 3 record (1, male); (2, female); (3, male)
          so when create foreign key for id of table b -> id of table a, record 3 of table b can't find any record of table a correspond.

          Comment

          Working...