If i have this structure:
table users
id_user
1
2
table lists
id_lists name_list users_id_user
1 Work 1
2 work 2
lists_has_users
users_id_user lists_id_lists
1 2
2 1
What I want is, when delete the id_lists, I also want to delete all the users that are members of that list in list_has_users
For example if i delete the id_lists 1, the lists_id_lists 1 should also be deleted.
At the moment i get: Cannot delete or update a parent row
How solve this?
It seems as though you have a
FOREIGN KEYconstraint defined which enforces referential integrity, and prohibits you from deleting a parent row if children exist. Modify your foreign key to includeON DELETE CASCADEto force deletion of child rows.Use
DESCRIBE lists_has_usersto get the FK’s symbol if you don’t know it.You may want to add
ON UPDATE CASCADEas well, so that thelists_has_usersrow changes if the id oflistsever changes.