ERROR 1216: Cannot add or update a child row: a foreign key constraint fails
Bonsoir,
j'ai l'erreur qui est dans le titre mais je ne comprends pas trop pourquoi et comment la corriger.
Au départ la table tDestination est vide
Code:
1 2
| mysql> select * from tDestination;
Empty set (0.00 sec) |
Ensuite, je teste la requete qui servira à remplir la table tDestination
Code:
1 2 3 4
| mysql> SELECT tTable.table_i_id, car_e_country, count(*)
-> FROM tCard NATURAL JOIN tTable NATURAL JOIN tUser
-> WHERE use_ee_actions LIKE '%stat%'
-> GROUP BY car_e_country; |
Le résultat de cette requete donne :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| +----------------+---------------+----------+
| table_i_id | car_e_country | count(*) |
+----------------+---------------+----------+
| 21168589893714 | France | 17 |
| 10142247654561 | Italie | 13 |
+----------------+---------------+----------+
2 rows in set (0.00 sec) |
Maitenant, je remplit la table tDestination mais là, ça coince ...
Code:
1 2 3 4 5 6 7
| mysql> REPLACE INTO tDestination(sta_i_id, des_e_country, des_i_nb)
-> SELECT tTable.table_i_id, car_e_country, count(*)
-> FROM tCard NATURAL JOIN tTable NATURAL JOIN tUser
-> WHERE use_ee_actions LIKE '%stat%'
-> GROUP BY car_e_country;
ERROR 1216: Cannot add or update a child row: a foreign key constraint fails
mysql> |
Le champ sta_i_id de la table tDestination est une clé étrangère d'une table nommé tStat.
Comment corriger cela ? J'essayes depuis cet après-midi, sans succès.
Merci