How to drop columns using Rails migration

前端 未结 20 786
执笔经年
执笔经年 2020-12-12 08:50

What\'s the syntax for dropping a database table column through a Rails migration?

20条回答
  •  甜味超标
    2020-12-12 09:27

    In a rails4 app it is possible to use the change method also for removing columns. The third param is the data_type and in the optional forth you can give options. It is a bit hidden in the section 'Available transformations' on the documentation .

    class RemoveFieldFromTableName < ActiveRecord::Migration
      def change
        remove_column :table_name, :field_name, :data_type, {}
      end
    end
    

提交回复
热议问题