Announcement

Collapse
No announcement yet.

SQL Error

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL Error

    Please take a look of my two table definition : Domain and DomainEquivalentList and then the code of inserting data in the "DomainEquivalentList" table. But I am getting the following error:

    SQL error:
    Cannot add or update a child row: a foreign key constraint fails

    Could you please help me?

    CREATE TABLE Domain
    (
    INDEX (Domain_ID),
    Domain_ID MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
    UNIQUE (Name),
    Name VARCHAR(255) NOT NULL,
    Description BLOB NOT NULL,
    PRIMARY KEY (Domain_ID)
    ) TYPE = INNODB;

    CREATE TABLE DomainEquivalentList
    (
    INDEX (DomainEquivalentList_ID),
    DomainEquivalentList_ID MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
    INDEX (Domain_ID),
    Domain_ID MEDIUMINT UNSIGNED NOT NULL,
    INDEX (Next_ID),
    Next_ID MEDIUMINT UNSIGNED,
    FOREIGN KEY (Domain_ID) REFERENCES Domain (Domain_ID) ON DELETE CASCADE,
    FOREIGN KEY (Next_ID) REFERENCES DomainEquivalentList (DomainEquivalentList_ID) ON DELETE CASCADE,
    PRIMARY KEY (DomainEquivalentList_ID)
    ) TYPE = INNODB;




    <?php
    require(".......");
    $link = mysql_connect($host,$user,$pass);
    if (!$link)
    die("Couldn't connect to MySQL");
    mysql_select_db($db)
    or die("Couldn't open $db: ".mysql_error());
    $table = "DomainEquivalentList";
    $Domain_ID = 5;
    $Next_ID = NULL;

    $query = "insert into $table values ('', '$Domain_ID', '$Next_ID')";
    $result = mysql_query($query);

    if (!$result)
    {
    print "<h1>SQL error:</h1>" .mysql_error();
    }

    else

    print "Inserted";

    ?>

  • #2
    Only one thread please:
    http://www.vbulletin.com/forum/showthread.php?t=76840
    Steve Machol, former vBulletin Customer Support Manager (and NOT retired!)
    Change CKEditor Colors to Match Style (for 4.1.4 and above)

    Steve Machol Photography


    Mankind is the only creature smart enough to know its own history, and dumb enough to ignore it.


    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X