I need to remove a few columns from my rails model which i already created and have some row entries in that model. How to do it? Any links which has details for modifying the schema in rails ? I'm using rails version 3.
+4
A:
To remove a database column, you have to generate a migration:
script/rails g migration RemoveColumns
Then in the self.up class method, remove your columns:
def self.up
remove_column :table_name, :column_name
end
You may want to add them back in the self.down class method as well:
def self.down
add_column :table_name, :column_name, :type
end
The [Rails Guide][1] for this goes into much more detail.
[1]: http://guides.rubyonrails.org/migrations.html"Rails Guide"
Jason stewart
2010-10-16 12:31:31
You don't have to specify `script/rails` with Rails 3. `rails g migration RemoveColumns` would suffice.
vonconrad
2010-10-16 12:35:12