Duplication possible:
2 requête FOREIGN KEY
Je crée un tableau et insère des données dans son tableau. Je souhaite définir deux clés étrangères sur ce tableau. J'écris cette requête.
ALTER TABLE SaleDetail
ADD CONSTRAINT FK1_ProductID
FOREIGN KEY (ProductID)
REFERENCES Product(ProductID),
ADD CONSTRAINT FK2_SaleID
FOREIGN KEY (SaleID)
REFERENCES Sale(SaleID);
il montre une erreur
Cannot add or update a child row: a foreign key constraint
fails (mc120200290.#sql-5f0_60, CONSTRAINT FK1_ProductID FOREIGN KEY (ProductID)
REFERENCES product (ProductID))
Réponses:
1 pour la réponse № 1Il me semble qu’il existe une ligne existante dans votre table SaleDetail avec un ProductID qui ne figure pas dans la table produit.