#1216 - Cannot add or update a child row

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
big_c147
Forum Newbie
Posts: 15
Joined: Wed Jun 22, 2005 9:32 am

#1216 - Cannot add or update a child row

Post by big_c147 »

Hi guys.

I have a mySQL database that I am using through phpmyadmin. It has about 13 tables in it. Most of the tables have a field called "username" which I have made a foreign key (linked to the key field in my username table). This works fine when I set it, however now I am trying to edit a username in the username table (the username is the key field in the username table) and have it update the other tables where it is present. But I get the following error message... "#1216 - Cannot add or update a child row: a foreign key constraint fails".

Any ideas how I can fix my problem?

Thanks
Craig
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Can we see your query?
big_c147
Forum Newbie
Posts: 15
Joined: Wed Jun 22, 2005 9:32 am

Post by big_c147 »

All i am trying to do is rename the Username which is the primary key in my user table. This is also present in other tables. for example....


Users Table
Username (PK)
other unrealted fields

Upload Table
(other fields)
Username (FK)

So when the username in the users table is changed it automatically updates the upload table to reflect the changes. However the error in my first post is returned.
Post Reply