...
...because there is row in ldap_group that is referencing the id in a row of the usergroup table we need to delete. Therefor taht row in the ldap_group table needs to be deleted first.
| Expand | ||
|---|---|---|
| ||
The row where id = 7 in th ldap_group table needs to be deleted first, before the row with the same id on the usergroup table (which also references that domain_id) can be deleted. |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
DELETE lg FROM ldap_group lg
JOIN usergroup ug ON lg.id = ug.id
WHERE ug.domain_id = 5; |
Once the above query has been executed successfully, can you then run..
| Code Block | ||||
|---|---|---|---|---|
| ||||
delete from usergroup where domain_id = 5 |
However, that may not be the end because there may be another table referencing rows on usergroup
Here you can use the same join query as above hiowever changing the table name in the first line to match the table name stated in the error above (tbl_policy), and make sure the column name on the second line is changed to group_id
| Code Block | ||||
|---|---|---|---|---|
| ||||
DELETE tp FROM tbl_policy tp JOIN usergroup ug ON tp.group_id = ug.id WHERE ug.domain_id = 5; |
If you then encounter a third level key constraint issue such as
Cannot delete or update a parent row: a foreign key constraint fails (`dualshield`.`tbl_policy_applications`, CONSTRAINT `FK61B4ED0FB3470AD4` FOREIGN KEY (`policy_id`) REFERENCES `tbl_policy` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT)
Then you need to run a query that inks all three tables together to find and delete the applications tied to the policies that belong to domain_id 5:
| Code Block | ||||
|---|---|---|---|---|
| ||||
DELETE tpa FROM tbl_policy_applications tpa
JOIN tbl_policy tp ON tpa.policy_id = tp.id
JOIN usergroup ug ON tp.group_id = ug.id
WHERE ug.domain_id = 5; |
...

