Philippe, j’ai testé ton code avec MySQL 5.7.23, et bien sûr j’ai eu droit au message :
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails
J’ai donc remplacé :
INSERT INTO test_fils (fils_id_pere, fils_nom)
VALUES (1, 'Nifnif'), (1, 'Nafnaf'), (2, 'Bob'), (2, 'Carole');
par :
INSERT INTO test_fils (fils_id_pere, fils_nom)
VALUES (3, 'Nifnif'), (3, 'Nafnaf'), (4, 'Bob'), (4, 'Carole');
Et cette fois-ci tout s’est évidemment bien passé.
Si pour toi ton INSERT inchangé fonctionne, c’est que l’intégrité référentielle n’est pas activée.
Partager