0

I'm using the statement insert into Oscar.MenuItem (idMenuItem, name, description, price, idCategory, code, sortIndex) select * from menItem;

The result is:

Error: Cannot add or update a child row: a foreign key constraint fails (`Oscar`.`MenuItem`, CONSTRAINT `fk_MenuItem_Category1` FOREIGN KEY (`idCategory`) REFERENCES `Category` (`idCategory`) ON DELETE NO ACTION ON UPDATE NO ACTION)
SQLState:  23000
ErrorCode: 1452

Please any1 with a solution to this help me.

my tables are as follows (Table MenuItem and Table Category)

Table MenuItem
idMenuItem INT NOT NULL AUTO INCREMENT
name VARCHAR(255)NOT NULL
description VARCHAR(512) NOT NULL
price DECIMAL(10) NOT NULL
idCategory INT NOT NULL
code VARCHAR(45) NOT NULL
sortIndex INT NOT NULL

Table Category
idCategory INT NOT NULL AUTO INCREMENT
name VARCHAR(255) NOT NULL
description VARCHAR(255) NOT NULL
idMenu INT NOT NULL
sortIndex INT NOT NULL

Edited by pritaeas: Added markdown

2
Contributors
1
Reply
13
Views
4 Years
Discussion Span
Last Post by pritaeas
1

You are trying to insert a row into the new menuitem table, that has a category ID, not yet in the category table. Make sure your new category table is filled correctly first.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.