I am very new to rails application. I need to change the column name of a table .. SO i browsed thru some sites and as thy mentioned i thought of writing migration file ..
class RenameNameToFirstnameInUsers < ActiveRecord::Migration
def self.up
rename_column 'users', 'name', 'first_name'
end
def self.down
rename_column 'users', 'first_name', 'name'
end
end
How to save this file and where ??
applicationname/db/migrate/
In what name i can save this ?? As far now i have seen many files there but all those have prefix of some big_number
And after saving this , how do i test it in my local??
the easiest way to do this is:
Rails3
rails generate migration RenameNameToFirstnameInUsers
Rails2
script/generate migration RenameNameToFirstnameInUsers
And then edit the created migration file, and migrate your db as normal.