----- Original Message ----- From: "VenuGopal Papasani" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Tuesday, September 05, 2006 12:28 AM
Subject: what this error was


Hi,
I was trying to import some of the data into the 'datavalue' table of my
database i was getting th following error

Error Code : 1452
Cannot add or update a child row: a foreign key constraint fails
(`gtest1/datavalue`, CONSTRAINT `FKEB92DC077A7A2FFA` FOREIGN KEY
(`dataElement`) REFERENCES `dataelement` (`id`))
(5428 ms taken)


My table structures:

dataelement  CREATE TABLE `dataelement`
(
              `id` int(11) NOT NULL
auto_increment,
              `name` varchar(255) NOT
NULL,
              `shortName` varchar(255) default
NULL,
              `description` varchar(255) default
NULL,
              `active` bit(1) default
NULL,
              `type` varchar(255) default
NULL,
              `aggregationOperator` int(11) default
NULL,
              `parent` int(11) default
NULL,
              `alternativeName` varchar(255) default
NULL,
              `code` varchar(255) default
NULL,
              PRIMARY KEY
(`id`),
              UNIQUE KEY `name`
(`name`),
              UNIQUE KEY `shortName`
(`shortName`),
              UNIQUE KEY `alternativeName`
(`alternativeName`),
              UNIQUE KEY `code`
(`code`),
              KEY `FKE1611C125DC41C92`
(`parent`),
              CONSTRAINT `FKE1611C125DC41C92` FOREIGN KEY (`parent`)
REFERENCES `dataelement` (`id`)
            ) ENGINE=InnoDB DEFAULT
CHARSET=utf8

----------

datavalue  CREATE TABLE `datavalue`
(
            `dataElement` int(11) NOT
NULL,
            `period` int(11) NOT
NULL,
            `source` varchar(255) NOT
NULL,
            `flag` varchar(255) default
NULL,
            `value` varchar(255) default
NULL,
            `storedBy` varchar(255) default
NULL,
            `timestamp` datetime default
NULL,
            `comment` varchar(255) default
NULL,
            PRIMARY KEY
(`dataElement`,`period`,`source`),

            KEY `FKEB92DC077F9CE9CC`
(`period`),
            KEY `FKEB92DC077A7A2FFA`
(`dataElement`),
            CONSTRAINT `FKEB92DC077A7A2FFA` FOREIGN KEY (`dataElement`)
REFERENCES `dataelement` (`id`),
            CONSTRAINT `FKEB92DC077F9CE9CC` FOREIGN KEY (`period`)
REFERENCES `period` (`id`)
          ) ENGINE=InnoDB DEFAULT
CHARSET=utf8


The message is pretty clear; a dataelement value on a row failed to satisfy the foreign key constraint during either an insert or an update.

Let's say that the dataelement value had a foreign constraint that limited the values to 'M' or 'F'. If you added a new row to the table and the value in the new dataelement column was anything but 'M' or 'F', you would have violated the foreign constraint and gotten that error. Or, if you had updated an existing row and tried to change the dataelement value to anything but 'M' or 'F', you would get that same message.

You need to look at the values that are allowable in this dataelement column and then see what value is actually being inserted or what the existing value is being changed to.

--
Rhino


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.7/437 - Release Date: 2006-09-04


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to