Hi, I've two tables, one called users and one called playerweapons.

In users it carries information and is defined by a Username field.

In playerweapons it has the same define with using Username.

I want it so when I update the Username field in users it will then update the username in playerweapons.

Here is the screenshot of the Users table and playerweapons table.

Users: http://pokit.org/get/img/ce10f6ee0db75165ddf4ddd4dca2e979.png
playerweapons: http://pokit.org/get/img/997ea313624ca26d57bb4dc4ffd4f346.png

I try to set it up but I get this error in the screenshot:

http://pokit.org/get/img/85c25f8aad2fe805fe0946e79395c53b.png

I hope you can help.

Thank you.

there are some username in playerwepons which does not exist in your users table, so it is not allowing you to add constraint. If you want to add contraint, you have to delete that usernames from weapon table which does not exists in your users table, or add that usernames in user table.

chaning username is not good practise, you can also refer ID column to playerweapons table , then you can join tables by ID to access information.

Ok, I have fixed that issue, but now when I edit the username data it comes up with an error.

There is a row with KyleSmith as the username and I want it to update the username in playerweapons to whatever I changed it to:

1452 - Cannot add or update a child row: a foreign key constraint fails (kyle.users, CONSTRAINT users_ibfk_1 FOREIGN KEY (Username) REFERENCES playerweapons (Username) ON UPDATE CASCADE)

You have created wrong refrecnes, it shows that username refrences playerweapon, actually it should refer to users, so delete that foreing key from users table and add that key to playerweapon

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.