I am trying to insert data into my DB and I keep getting the "ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails" on 1 insert command. I believe it has to do with the FKs I used when I created the table. But I am not sure how to fix it. Any suggestions would be awesome.
Original Create table commands: REATE TABLE Donut (DonutID int, DonutName VARCHAR(25) not null, Description VARCHAR(25) not null, UnitPrice decimal(4,2) not null, PRIMARY KEY (DonutID) ) ;
CREATE TABLE Customer ( CustomerID INT not null, FirstName VARCHAR(20) not null, LastName VARCHAR(20) not null, StreetAddress VARCHAR(20) not null, Apt VARCHAR(20), City VARCHAR(20) not null, State VARCHAR(2) not null, ZipCode VARCHAR(5) not null, HomePhone VARCHAR(10) not null, MobilePhone VARCHAR(10) not null, OtherPhone VARCHAR(10), PRIMARY KEY(CustomerID) ) ;
CREATE TABLE Orders ( OrderID int not null, CustomerID int, OrderDate Date not null, Notes VARCHAR(100), PRIMARY KEY (OrderID), FOREIGN KEY (CustomerID) REFERENCES Customer (CustomerID) ) ;
CREATE TABLE OrderItem ( OrderID INT, DonutID INT, Qty SMALLINT not null, PRIMARY KEY(OrderID, DonutID), FOREIGN KEY (OrderID) REFERENCES Orders (CustomerID), FOREIGN KEY (DonutID) REFERENCES Donut (DonutID) ) ;
Insert command that is failing: INSERT INTO OrderItem (OrderID,DonutID,Qty) VALUES (991,1,12), (992,2,500), (993,3,6);