Ajout de deux foreign key

Résolu/Fermé
madeog Messages postés 74 Date d'inscription vendredi 12 octobre 2018 Statut Membre Dernière intervention 2 mars 2021 - 10 mars 2019 à 05:50
 Madog - 10 mars 2019 à 14:41
Bonjour,
j'essaie d'ajouter à la table enfant deux cles secondaire id_parent1 et id_parent2
j"ai ce message d'erreur pouvez vous m'aider

[/contents/1058-sql-modification-de-table alter table] enfant add constraint fk_enfant_parent_id_parent1_id_parent2 foreign key (id_parent1, id_parent2) references parents(id_parent1,id_parent2) on delete cascade on update restrict;
ERROR 1005 (HY000): Can't create table `bellefamille`.`#sql-2ee0_2` (errno: 150 "Foreign key constraint is incorrectly formed")


enfant | CREATE TABLE `enfant` (
  `id_enfant` int(11) NOT NULL AUTO_INCREMENT,
  `nom` varchar(100) NOT NULL,
  `prenoms` varchar(255) DEFAULT NULL,
  `date_nais` date DEFAULT NULL,
  `id_parent1` int(11) DEFAULT NULL,
  `id_parent2` int(11) DEFAULT NULL,
  PRIMARY KEY (`id_enfant`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1



 enfant_local | CREATE TABLE `enfant_local` (
  `id_enfant` int(11) NOT NULL AUTO_INCREMENT,
  `id_local` int(11) NOT NULL,
  PRIMARY KEY (`id_enfant`,`id_local`),
  KEY `enfant_local_ibfk_1` (`id_enfant`),
  KEY `enfant_local_ibfk_2` (`id_local`),
  CONSTRAINT `enfant_local_ibfk_1` FOREIGN KEY (`id_enfant`) REFERENCES `enfant` (`id_enfant`) ON DELETE CASCADE,
  CONSTRAINT `enfant_local_ibfk_2` FOREIGN KEY (`id_local`) REFERENCES `local` (`id_local`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 |


Configuration: Windows / Firefox 65.0

2 réponses

yg_be Messages postés 22726 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 476
10 mars 2019 à 14:21
bonjour, as-tu essayé de configurer deux contraintes, une sur chaque clé?
0
Oui
0