Questions tagged [mysql-error-1452]

MySql error #1452 - Cannot add or update a child row: a foreign key constraint fails

70 questions
240
votes
21 answers

Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails

I'm having a bit of a strange problem. I'm trying to add a foreign key to one table that references another, but it is failing for some reason. With my limited knowledge of MySQL, the only thing that could possibly be suspect is that there is a…
Zim
  • 4,971
  • 7
  • 23
  • 19
173
votes
23 answers

ERROR 1452: Cannot add or update a child row: a foreign key constraint fails

I have created tables in MySQL Workbench as shown below : ORDRE table: CREATE TABLE Ordre ( OrdreID INT NOT NULL, OrdreDato DATE DEFAULT NULL, KundeID INT DEFAULT NULL, CONSTRAINT Ordre_pk PRIMARY KEY (OrdreID), CONSTRAINT Ordre_fk…
user3289677
  • 1,731
  • 2
  • 10
  • 3
20
votes
10 answers

MySQL - Cannot add or update a child row: a foreign key constraint fails

This seems to be a common error, but for the life of me I can't figure this out. I have a set of InnoDB user tables in MySQL that are tied together via foreign key; the parent user table, and a set of child tables that store email addresses,…
Paul Mennega
  • 10,049
  • 19
  • 67
  • 109
7
votes
2 answers

Foreign key constraint error 1452 in MySQL - Magento import

i am trying to import a sql dump of magento along with some product data and i get this foreign key constraint error: `ERROR 1452 (23000) at line 231680: Cannot add or update a child row: a foreign key constraint fails: `magento`.`#sql-b33_27`,…
Nithin
  • 513
  • 2
  • 12
  • 28
7
votes
1 answer

Handling database integrity

I'm introducing database integrity using innodb constraints in the next version of my application. Everything goes well, but some of my tables have records with deleted references (dead records) and because of them I can't add constraints to the…
Silver Light
  • 37,827
  • 29
  • 116
  • 159
7
votes
3 answers

Why 'foreign key constraint fails' when foreign key exists?

I have a simple query UPDATE `t_timecard_detail` SET `timeoff_request_id` = 'adad8e0d-c22b-41c3-a460-6cf982729299' WHERE `id` = 'cfc7a0a1-4e03-46a4-af89-069a0661cf55'; which gives this error ERROR 1452 (23000): Cannot add or update a child row: a…
Anurag Uniyal
  • 77,208
  • 39
  • 164
  • 212
6
votes
5 answers

ERROR 1452: Cannot add or update a child row: a foreign key constraint fails

I have created two tables in MySQL 5.6.11 as shown below by means of MySQL Workbench 5.2.47. The country table: delimiter $$ CREATE TABLE `country` ( `id` int(11) NOT NULL AUTO_INCREMENT, `country_name` varchar(45) DEFAULT NULL, PRIMARY KEY…
Tiny
  • 24,933
  • 92
  • 299
  • 571
4
votes
1 answer

MySQL Error Code 1452 Foreign Key Constraint

I'm receiving an error when I attempt to create two tables. There was a multivalued dependency, so I separated the tables and came up with this: CREATE TABLE NAME ( NameID Integer NOT NULL AUTO_INCREMENT, Name varChar(255) …
Archibald
  • 414
  • 1
  • 7
  • 20
4
votes
3 answers

Trying to add foreign key in mysql with heidisql

I've been trying to add a foreign key to my table using heidisql and I keep getting the error 1452. After reading around I made sure all my tables were running on InnoDB as well as checking that they had the same datatype and the only way I can add…
randomdice101
  • 41
  • 1
  • 2
3
votes
2 answers

Creating a foreign key in MySQL produces error:

I'm trying to create a foreign key on a table in MySQL and I'm getting a strange error that there seems to be little info about in any of my searches. I'm creating the key with this (emitted from mysql workbench 5.2): ALTER TABLE `db`.`appointment`…
Steven Evers
  • 15,439
  • 19
  • 73
  • 119
3
votes
3 answers

MySQL Foreign key constraint - Error 1452 - Cannot add or update child row

I've used the other posts on this topic, but I'm having no luck. Here's the code I execute: UPDATE tblOrderItems SET `ItemID` = 0004 WHERE `OrderNum`= 203 AND `OrderItemID` = 26 Here's my error: Error Code: 1452. Cannot add or update a child row: a…
calvin
  • 809
  • 1
  • 14
  • 22
3
votes
2 answers

Getting ERROR 1701, ERROR 1452 and ERROR 1305 errors in MySQL - Need some expertise

This is my first real crack at making a database in Third Normal Form. I managed to create the DDL script ok (I had the logical model verified to 3NF before I went ahead and built the script) but I get a whole lot of errors I am unsure of fixing. I…
Rob
  • 1,192
  • 3
  • 19
  • 34
2
votes
2 answers

Foreign Key Failure

Ok, so I've been trying to figure out why I keep getting this specific error. MySql keeps giving me error code 1452. Cannot add or update a child row. My tables are as such. CREATE TABLE IF NOT EXISTS `ecommerce`.`departments` ( `id` INT NOT NULL…
David Landes
  • 356
  • 1
  • 2
  • 10
2
votes
2 answers

MySQL Error 1452 - can't insert data

I am inserting some data into the following MySQL tables: CREATE TABLE genotype ( Genotype VARCHAR(20), Fitness FLOAT NULL, Tally INT NULL, PRIMARY KEY (Genotype) )ENGINE=InnoDB; CREATE TABLE gene ( Gene VARCHAR(20), E FLOAT NOT NULL, Q2 FLOAT NOT…
Lisa
  • 321
  • 1
  • 8
  • 15
2
votes
3 answers

mysql - what does this error mean?

I do not require this error to be solved. I just need to understand what it means so I can approach it myself. Cannot add or update a child row: a foreign key constraint fails (`db`.`transaction`, CONSTRAINT `transaction_ibfk_2` FOREIGN KEY…
JasonS
  • 4,460
  • 15
  • 54
  • 70
1
2 3 4 5