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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.