I wrongly named one column as hased_password, should have been hashed_password instead. Can i use migration to correct it?
A:
http://api.rubyonrails.org/classes/ActiveRecord/Migration.html
Under "Available Transformations"
rename_column(table_name, column_name, new_column_name): Renames a column but keeps the type and content.
James Manning
2010-01-02 16:26:03
+7
A:
rename_column :table, :old_column, :new_column
Try dizzy, easier for those quick references needs.
Update:
You'll probably want to create a separate migration to do this. (Rename FixColumnName as you will)
script/generate migration FixColumnName
# creates db/migrate/xxxxxxxxxx_fix_column_name.rb
Then edit the migration to do your will.
# db/migrate/xxxxxxxxxx_fix_column_name.rb
class FixColumnName < 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 or do nothing
end
end
Then just db:migrate
as usual or however you go about your business.
nowk
2010-01-02 16:31:20
Thanks! Can I know how do I make use of this command? Do I need to add any code to the migration file or there is a command that I need to execute from terminal? Thanks
2010-01-02 16:36:08
I put up a quick example for you.
nowk
2010-01-02 17:13:54
Many thanks for this!
AlexC
2010-09-25 01:45:10
A:
imo in this case better use rake db:rollback
. Then edit your migration and again type
rake db:migrate
elf.xf
2010-01-03 00:55:51