The proper way to rename a column in Rails is to generate a migration. This
migration should be named
As an example, say that you want to generate a migration that renames the column
acct_balance in the
balances table. To do this, first generate a migration named using the following pattern:
Then, open the migration that was just created at
db/migrate/xxxxxxxxxx_change_checking_acct_balance_to_acct_balance.rb and edit it to rename the columns.
1 2 3 4 5 class ChangeCheckingAcctBalanceToAcctBalance < ActiveRecord::Migration def change rename_column :balances, :checking_acct_balance, :acct_balance end end
The patten for the
rename_column portion is
def change method is only available in Rails 3.1 and above. For versions of Rails prior to Rails 3.1, the
def up and
def down methods must be used to explicitly describe the up and down migrations.