How to drop columns using Rails migration

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

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

相关标签:
20条回答
  • 2020-12-12 09:46

    remove_column in change method will help you to delete the column from the table.

    class RemoveColumn < ActiveRecord::Migration
      def change
        remove_column :table_name, :column_name, :data_type
      end
    end
    

    Go on this link for complete reference : http://guides.rubyonrails.org/active_record_migrations.html

    0 讨论(0)
  • 2020-12-12 09:46

    Heres one more from rails console

    ActiveRecord::Migration.remove_column(:table_name, :column_name)

    0 讨论(0)
提交回复
热议问题