class ChangeReferenceContactContactgroup < ActiveRecord::Migration def self.up # move the reference between contacts..contactgroups the other way round execute "alter table contactgroups drop foreign key fk_contactgroups_contacts" remove_column :contactgroups, :contact_id add_column :contacts, :contactgroup_id, :integer, :null => false execute "alter table contacts add constraint fk_contacts_contactgroups foreign key (contactgroup_id) references contactgroups(id)" end def self.down end end