fixes #2421 missing has_many :hostgroups, fixes #2422 :before_destroy gotcha, :fixes #2400 foreign keys

The migration will fail if there are orphaned foreign keys.

Note, there is no foreign keys on the database level for polymorphic associations.