remove a table column rails code example

Example 1: how to remove columns from rails

rails generate migration RemoveFieldNameFromTableName field_name:datatype

remove_column :table_name, :column_name

Example 2: how to delete a table in rails

rails g migration DropProducts

class DropProducts < ActiveRecord::Migration
  def change
    drop_table :products
  end
end

Example 3: rails migration remove column

rails g migration Remove..From.. col1:type col2:type col3:type

#Exemple :

rails g migration RemoveCountryFromSampleApps country:string

Example 4: rails remove column

remove_column :table_name, :column_name

Tags:

Ruby Example