MySql error #1451 - Cannot delete or update a parent row: a foreign key constraint fails
Questions tagged [mysql-error-1451]
14 questions
14
votes
4 answers
In what order are ON DELETE CASCADE constraints processed?
Here is an example of what I've got going on:
CREATE TABLE Parent (id BIGINT NOT NULL,
PRIMARY KEY (id)) ENGINE=InnoDB;
CREATE TABLE Child (id BIGINT NOT NULL,
parentid BIGINT NOT NULL,
PRIMARY KEY (id),
KEY (parentid),
CONSTRAINT…

Matt Solnit
- 32,152
- 8
- 53
- 57
4
votes
2 answers
ERROR 1451: Cannot delete or update a parent row: a foreign key constraint fails
CREATE TABLE `categories` (
`idcategories` INT NOT NULL AUTO_INCREMENT ,
`idparent` INT NULL ,
`description` VARCHAR(45) NULL ,
PRIMARY KEY (`idcategories`) );
ALTER TABLE `categories`
ADD CONSTRAINT `FK_idparent`
FOREIGN KEY…

Simone Conti
- 544
- 3
- 9
- 20
3
votes
1 answer
SQL Error during Shopware 6 installation when choosing CHF as default currency
For a Swiss based client I'm trying to install a new Shopware 6 store. During the configuration phase I get a SQL-Integrity error when changing the default currency to CHF. However when I'm trying to install with the default settings (i.e. EUR as…

Janakan
- 61
- 2
3
votes
2 answers
mysql error 1451
I have mysql error with code 1451.
Cannot delete or update a parent row: a foreign key constraint fails (online_store_admin.osa_admin_logs, CONSTRAINT fk_admins_logs FOREIGN KEY (aid) REFERENCES osa_admins (aid))
here sql statement :
drop table…

crazymob
- 143
- 3
- 3
- 8
3
votes
1 answer
Grails GORM and MYSQL cascade delete problem
I have a table User that has many child tables defined in User class under the static hasMany
grails.
I have no problem when doing User.get(3).delete() in grails. It automatically delete that user and all its child table rows.
But when I want to…

Alan McCloud
- 631
- 2
- 13
- 20
2
votes
1 answer
Error code: 1451 with 2 primary keys
I cannot run the following statement:
delete from UT_Session where my_id='5146' and upgrade_time='2016-01-03 17:25:18'
Since I get:
Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (`Upgrade_tool`.`pre_tasks`,…

Yosi Tagger
- 67
- 5
2
votes
1 answer
Cannot delete or update a parent row - JPA with Hibernate
I have a database in which all of the tables have been generated by Java JPA/Hibernate code. I need to update several tables in my database in a fashion similar to this,
UPDATE Department SET id=100000 WHERE id=0;
Unfortunately this results in the…

Donny
- 89
- 1
- 4
- 9
1
vote
6 answers
Can not delete a row in the table (MySQL)
Dear all, I have a problem in MySQL:
I failed to execute DELETE FROM users where user_id ='1'; in the MySQL CLI.
So I tried in the phpMyAdmin:
Use the GUI to delete a row, I got this:
SQL query:
DELETE FROM `health_portal`.`users` WHERE…

manxing
- 3,165
- 12
- 45
- 56
1
vote
3 answers
Mysql error 1451 but no line with referenced id can be found
I need to delete a row from A table. I get a 1451 error which means a constraint failed. But when i try to find this relation, nothing comes up.
mysql> delete from A where id=961;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign…

Shakealot
- 133
- 10
1
vote
1 answer
foreign key problem with my database
I am creating a social networking site and am working on a friends table and dont know what Im doing wrong.
I have a users(userId, name - userId is primary key) and another table called friends(friend1, friend2, status). friend1 and friend2 are…

Dom
- 1,018
- 2
- 11
- 20
1
vote
1 answer
Zend Framework - Problem with Database Table Recursive Cascading Deletes
My situation may be a bit abnormal, but I have foreign keys defined in my MySQL database, while enforcing referential integrity in the Zend_Db_Table classes. The tables use the InnoDB storage engine.
When deleting a record, the Zend Framework will…

Sonny
- 8,204
- 7
- 63
- 134
0
votes
1 answer
Confusing mysql problem
I have got a problem with two tables:
CREATE TABLE IF NOT EXISTS `addresses` (
`adr_id` int(11) NOT NULL auto_increment,
`per_id` int(11) NOT NULL,
`adr_street` varchar(50) NOT NULL,
`adr_houseno` int(11) default NULL,
…

sanders
- 10,794
- 27
- 85
- 127
0
votes
0 answers
MySQL 5.5 - error 1451- Data Inconsistency
On MYSQL database version 5.5, I have tables with following foreign key constraint:
CONSTRAINT fk_parent_child_id FOREIGN KEY (child_id ) REFERENCES parent (id ) ON DELETE NO ACTION ON UPDATE NO ACTION
It has been noticed that…

Shymaa Ibrahim
- 1
- 2
0
votes
0 answers
mysql foreign key ERROR 1451 update cascade not happening
I am trying to update a field that is referenced as a foreign key in another table.
mysql> update Maintenance set contract='95096916-OLD' where contract='95096916';
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign
key…

CHB
- 1