Mysql
 sql >> Base de données >  >> RDS >> Mysql

MySQL - Impossible d'ajouter ou de mettre à jour une ligne enfant :une contrainte de clé étrangère échoue

J'ai résolu mon 'échec de la contrainte de clé étrangère ' problèmes en ajoutant le code suivant au début du code SQL (c'était pour importer des valeurs dans une table)

SET @[email protected]@CHARACTER_SET_CLIENT;
SET @[email protected]@CHARACTER_SET_RESULTS;
SET @[email protected]@COLLATION_CONNECTION;
SET NAMES utf8;
SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';
SET @[email protected]@SQL_NOTES, SQL_NOTES=0; 

Puis ajouter ce code à la fin du fichier

SET [email protected]_SQL_MODE;
SET [email protected]_FOREIGN_KEY_CHECKS;
SET [email protected]_UNIQUE_CHECKS;
SET [email protected]_CHARACTER_SET_CLIENT;
SET [email protected]_CHARACTER_SET_RESULTS;
SET [email protected]_COLLATION_CONNECTION;
SET [email protected]_SQL_NOTES;