I have a BASH program that inserts into my DB somes lines. Unfortunately, when MYSQL encounter an error(especially foreign key constraint errors), the entire SQL request stops.
Isn't there a way to skip the lines where the foreign key constraint doesn't apply, and keep adding the others?
insertVtigerInfos() {
$mysql -h $db_address -u $db_user -p$db_passwd $db_name -e "delete from $db_vtiger_name;load data local infile '$vtiger_temporary_file' REPLACE INTO TABLE $db_vtiger_name fields terminated by ';'"
}
----------------------démarrage---------------------------------
Tue May 6 16:03:13 CEST 2014
ERROR 1452 (23000) at line 1: Cannot add or update a child row: a foreign key constraint fails (`RH2QUALIF`.`info_vtiger`, CONSTRAINT `info_vtiger_ibfk_1` FOREIGN KEY (`nom_caisse`) REFERENCES `definition_ip_switch` (`nom_caisse`) ON DELETE CASCADE ON UPDATE CASCADE)
-------------------------fin------------------------------------
Tue May 6 16:03:14 CEST 2014
Updating thread with sample : Table toward whom the foreign key constraint applies :
+-------------+------------+
| nom_caisse | quat_octet |
+-------------+------------+
| BCP | NULL |
| CEA | NULL |
Table having the foreign key constraint :
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| code_site | varchar(32) | NO | PRI | NULL | |
| nom_caisse | varchar(32) | NO | MUL | NULL | |
| ip_routeur | varchar(32) | NO | | NULL | |
Data trying to be inserted :
131001M0;CEA;<ip>
131001G0;CEALS;<ip>
When mysql tries to insert the rows, the 1st is OK, the 2nd is not (because CEALS is not in the table which the foreign key is. But mysql doesn't add ANY row because he found one not matching... I just want it to add the 1st row...