Well in fact from what I understood of the error is that you were trying to delete a resource that was linked to a parent already removed, hence the error.
I could fix that but not sure what makes the most sense, remove the child resources upon deletion of a parent resource or just avoid the error from popping ?