fixes #6216 - foreign key errors such as deleting a subnet that is associated with a host group and others

@domcleal, this fixes http://projects.theforeman.org/issues/4416
Do you want me to make a separate PR just for this?