I am importing data from a .csv file using LOAD DATA LOCAL INFILE into the following two tables:
CREATE TABLE `mgap_ska` (
`mgap_ska_id` int(11) NOT NULL,
`mgap_ska_id_name` varchar(255) DEFAULT '',
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
KEY `account_manager_fk` (`account_manager_id`),
CONSTRAINT `account_manager_fk` FOREIGN KEY (`account_manager_id`) REFERENCES `mgap_account_managers` (`account_manager_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mgap_orders` (
`mgap_ska_id_name` varchar(255) DEFAULT '',
`mgap_item_number` int(11) NOT NULL,
`skarowid` int(11) NOT NULL,
KEY `skarow_fk` (`skarowid`),
CONSTRAINT `skarow_fk` FOREIGN KEY (`skarowid`) REFERENCES `mgap_ska` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
As you can see I have a primary key called 'id' in the first column and Im trying to relate it to the 'skarowid' in the second table. The idea is to duplicate the 'id' field from the first table into the second table under the 'skarow' column. I need to relate the row ids from the first table to order ids in the second. The 'id' in the first table Auto_Increments to establish the separate row ids and I need those row ids to relate to orders in the second table.
Note: Values for 'id' and 'skarow' DO NOT come from the .csv file.
Im getting the following error when I import the file: Cannot add or update a child row: a foreign key constraint fails (mgaptool
.mgap_orders
, CONSTRAINT skarow_fk
FOREIGN KEY (skarowid
) REFERENCES mgap_ska
(id
)
Any help is appreciated.