todd hewett wrote:
mysql> INSERT INTO BOARD_SERIAL_NUMBER (BOARD_SERIAL_NUMBER)
mysql> VALUES(36534);
ERROR 1216: Cannot add a child row: a foreign key constraint fails
Can you please post the output of:
SHOW CREATE TABLE BOARD_SERIAL_NUMBER;
mysql> SHOW CREATE TABLE BOARD_SERIAL_NUMBER;
--------------------------------------------+
| BOARD_SERIAL_NUMBER | CREATE TABLE `BOARD_SERIAL_NUMBER` (
`BOARD_SERIAL_NUMBER_PK` int(10) unsigned NOT NULL auto_increment,
`VCS_PO_NUMBER_PK` int(10) unsigned NOT NULL default '0',
`BOARD_SERIAL_NUMBER` varchar(255) NOT NULL default '',
PRIMARY KEY (`BOARD_SERIAL_NUMBER_PK`,`VCS_PO_NUMBER_PK`),
KEY `BOARD_SERIAL_NUMBER_FKIndex1` (`VCS_PO_NUMBER_PK`),
FOREIGN KEY (`VCS_PO_NUMBER_PK`) REFERENCES
`productiontrack.VCS_PO_NUMBER` (`VCS_PO_NUMBER_PK`) ON DELETE CASCADE
) TYPE=InnoDB |
+---------------------+-----------------------------------------------------
Because you're not specifying a value for VCS_PO_NUMBER_PK in that
INSERT statement, it will default to 0. It is a foreign key referencing
the 'productiontrack.VCS_PO_NUMBER' table, which I bet doesn't have a
row with VCS_PO_NUMBER_PK equal to 0. Hence the foreign key constraint
fails.
You need to either:
1/ Specify the relevant value for VCS_PO_NUMBER_PK in your insert
statement, like
INSERT INTO BOARD_SERIAL_NUMBER (BOARD_SERIAL_NUMBER, VCS_PO_NUMBER_PK)
VALUES (36534, 12345);
2/ Remove the foreign key constraint
3/ Create a row in VS_PO_NUMBER where VCS_PO_NUMBER_PK is equal to 0
You should probably take option 1 if possible.
--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]