How do you make remove_column reversible?

后端 未结 2 696
旧时难觅i
旧时难觅i 2021-02-03 17:43

I have a migration that removes a column:

def change
  remove_column :foos, :bar, :boolean
end

When I try to rake db:rollback that

2条回答
  •  有刺的猬
    2021-02-03 17:54

    Instead of using change, you use up and down methods to your migration:

    def up
      remove_column :foos, :bar
    end
    
    def down
      add_column :foos, :bar, :boolean
    end
    

提交回复
热议问题