私は次のActiveRecord移行を持っています:
class CreateSubjects < ActiveRecord::Migration
def self.up
create_table :subjects do |t|
t.string :title
t.timestamps
end
change_table :projects do |t|
t.references :subjects
end
end
def self.down
drop_table :subjects
remove_column :projects, :subjects_id #defeats the purpose of having references
end
end
私は実際にそのreferences
スタイルが好きです。残念ながらreferences
、self.down
セクションで同等のロールバックを見つけることができませんでした。私が書くなら、私も書くremove_column :projects, :subjects_id
ことができますt.integer :subjects_id
、それはそれをより安全にするでしょう。