J'ai une table qui référence une réservation et un produit, mais je ne peux pas ajouter de clé étrangère.Clés étrangères avec mySQL
Voici le tableau:
CREATE TABLE IF NOT EXISTS `resa_product` (
`id_reservation` int(10) NOT NULL,
`id_business` int(10) NOT NULL,
`id_category` int(10) NOT NULL,
`id_product` int(10) NOT NULL,
`quantity` int(11) NOT NULL,
PRIMARY KEY (`id_reservation`,`id_business`,`id_category`,`id_product`),
KEY `resa_prod_index` (`id_business`,`id_category`,`id_product`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Le tableau produit:
CREATE TABLE IF NOT EXISTS `product` (
`id_business` int(10) NOT NULL,
`id_product` int(10) NOT NULL AUTO_INCREMENT,
`id_category` int(10) NOT NULL,
`nom` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
...
PRIMARY KEY (`id_product`,`id_category`,`id_business`),
KEY `id_category` (`id_category`),
KEY `id_business` (`id_business`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;
mais lorsque je tente, je reçois le numéro 150 de mySQL:
ALTER TABLE `resa_product`
ADD FOREIGN KEY (`id_business`, `id_category`, `id_product`)
REFERENCES `product`(`id_business, `id_category`, `id_product`)
ON UPDATE CASCADE
ON DELETE RESTRICT;
Je don Je ne comprends pas pourquoi je ne peux pas insérer cette touche composée, bien que j'aie ajouté un index. Est-ce que quelqu'un a une idée?
Merci pour votre aide
À quoi ressemble la table de produit s'il vous plaît? – gbn
À quoi ressemble votre table 'product'? –