Please help I've tried everything and every single solution on StackOverflow and other sites on Internet.
I've created 2 tables (categories
) and (items
) and inserted this row into categories:
INSERT INTO categories (Name, Description, Ordering, Visibility, Allow_Comments, Allow_Ads)
VALUES ('Wheel', 'Custom', 1, 0, 0, 0)
Successfully inserted.
Then created the Foreign key:
ALTER TABLE items
ADD CONSTRAINT Cat_1
FOREIGN KEY(Cat_ID)
REFERENCES categories(ID)
ON UPDATE CASCADE
ON DELETE CASCADE;
Successful Created.
The problem is when I'm trying to insert rows into items got the error message.
INSERT INTO items (Name, Description, Type, Color, Certified, Quantity, Date, Price)
VALUES ('Test', 'Test', 'Wheel', 'Test', 'Test', 1, NOW(), 100);
1452 Cannot add or update a child row: a foreign key constraint fail
Tried to add images but didn't work. I've double checked the values.