Ajout de deux foreign key
Résolu
madeog
Messages postés
74
Date d'inscription
Statut
Membre
Dernière intervention
-
Madog -
Madog -
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
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
A voir également:
- Ajout de deux foreign key
- Key windows 10 - Guide
- Nombre de jours entre deux dates excel - Guide
- Deux ecran pc - Guide
- Comment faire deux colonnes sur word - Guide
- Ajout rapide snap - Forum Snapchat
2 réponses
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
bonjour, as-tu essayé de configurer deux contraintes, une sur chaque clé?