How to remove a column from my Rails model?

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 for this goes into much more detail.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)