I have created tables in MySQL Workbench as shown below :
ORDRE table:
CREATE TABLE Ordre (
OrdreID INT NOT NULL,
OrdreDato DA
While inserting the foreign key attribute values, first verify the attributes type, as well as primary key attribute value in the parent relation, if the values in parent relation matches, then you can easily insert/update child attribute values.
In my case the tables were perfectly consistent.
Anyway I was getting this error because I created (by accident) more than one FK constraint on the same field.
I run the following query to show all the keys:
SELECT *
FROM information_schema.table_constraints
WHERE constraint_schema = 'my_db_name'
and I deleted the wrong ones with the following query:
ALTER TABLE my_table
DROP FOREIGN KEY wrong_fk_constraint;
You can check it also running this query:
SHOW CREATE TABLE my_table;
ERROR 1452: Cannot add or update a child row: a foreign key constraint fails.... if this type of error occur : then First of all goto this table and check in setting > if Engine is: InnoDB then change its to MyISAM
(and delete references foreign constraint)
You must delete data in the child table which does not have any corresponding foreign key value to the parent table primary key .Or delete all data from the child table then insert new data having the same foreign key value as the primary key in the parent table . That should work . Here also a youtube video
you should insert at least one raw in each tables (the ones you want the foreign keys pointing at) then you can insert or update the values of the foreign keys
First allow NULL on the parent table and set the default values to NULL. Next create the foreign key relationship. Afterwards, you can update the values to match accordingly