473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.



I have a table which has a foreign key relationship with itself. I
want and expect my updates to cascade (deletes definitely cascade as
expected) but instead I just get error 1217: foriegn key error.

I have written example code to use in reproducing the problem:
# Create the table
drop TABLE IF EXISTS person;
create table person (
parent VARCHAR(50) NOT NULL,
INDEX parent_ind(parent),
REFERENCES person(name) # this makes it so that when a page is deleted/updated, so are all it's sub-pages

# Insert some example data
INSERT INTO person (name,parent) VALUES ('Grandpa', 'Grandpa');
INSERT INTO person (name,parent) VALUES ('John', 'Grandpa');
INSERT INTO person (name,parent) VALUES ('Baby Bob', 'John');

mysql> select * from person;
| name | parent |
| Grandpa | Grandpa |
| John | Grandpa |
| Baby Bob | John |

# Attempt the update (this fails with error 1217)
UPDATE person SET name='Mary' where name='John';
# I expect to end up with these values:
mysql> select * from person;
| name | parent |
| Grandpa | Grandpa |
| Mary | Grandpa |
| Baby Bob | Mary |

I have verified that deletes cascade as expected.
After attempting the update query, SHOW INNODB STATUS reports the following:
030805 19:28:57 Transaction:
TRANSACTION 0 13261, ACTIVE 0 sec, OS thread id 664 updating or deleting, thread declared inside InnoDB 499
3 lock struct(s), heap size 320, undo log entries 1
MySQL thread id 307, query id 2804 localhost root Updating
UPDATE person SET name='Mary' where name='John'
Foreign key constraint fails for table test/person: ,
Trying an update, possibly causing a cyclic cascaded update
in the child table, in parent table, in index PRIMARY tuple:
0: len 4; hex 4a6f686e; asc John;; 1: len 6; hex 0000000033cd; asc ....3.;; 2:
len 7; hex 000000003700f4; asc ....7.¶;; 3: len 7; hex 4772616e647061; asc Grandpa;;
But in child table test/person, in index parent_ind, there is a record:
RECORD: info bits 0 0: len 4; hex 4a6f686e; asc John;; 1: len 8; hex 4261627920426f62; asc Baby Bob;;

I have verified that the problem is not related to the self-referential row at
the start by turning off foreign key checks, deleting that row, turning
foreign_key_checks back on and then attempting the update again. This still
produces error 1217.

Is this an official mysql bug, or am I missing something?

Any help is greatly appreciated,
--Fraser Hanson

MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
0 5877

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: john | last post by:
Hi, I'm using: - Red Hat 9 - MySQL 3.23.56 create table t1( id integer not null, primary key(id)) type = INNODB;
by: Gunnar Vřyenli | last post by:
Hi! For the sake of simplicity, I have three tables, Employee, Department and Work Employee >---- Department \ / \ / ^ ^ Work
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid,...
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and...
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
by: fuimens | last post by:
Hi, With mysql-4.0.20, I have a problem inserting data with foreign key references, MySQL saying ERROR 1216: Cannot add or update a child row: a foreign key constraint fails The message is...
by: nassim.bouayad.agha | last post by:
Hello, here is my table declaration : CREATE TABLE staff_member( pay_id varchar(64) NOT NULL default '', manager_pay_id varchar(64), location_name varchar(64), first_name varchar(64) NOT NULL...
by: adithi | last post by:
My Table Structure is: Table A Table B Table C colA -PK Col B-PK Col C-PK Col B-FK ...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.