Wednesday, 3 September 2014

Rename Database Column in a Rails Migration

rename_column :table_name, :old_column_name, :new_column_name
Rails g migration ChangeColumnName
# creates  db/migrate/xxxxxxxxxx_change_column_name.rb

# db/migrate/xxxxxxxxxx_change_column_name.rbclass ChangeColumnName < ActiveRecord::Migration
  def self.up
    rename_column :table_name, :old_column, :new_column
  end

  def self.down
    # rename back if you need or do something else
  end
end

No comments:

Post a comment