Web Development

Sometimes you aimlessly create a table and you’d want to change it. Here’s how to rename a table in Rails 3 and higher.

Rails 3

class RenameOldTable < ActiveRecord::Migration
  def self.up
    rename_table :old_table, :new_table
  end
  def self.down
    rename_table :new_table, :old_table
  end
end

Rails 3.1+

Rails 3.1 and above offers a shorter alternative to renaming tables

class RenameOldTable < ActiveRecord::Migration
  def change
    rename_table :old_table_name, :new_table_name
  end
end