Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop columns using Rails migration

What's the syntax for dropping a database table column through a Rails migration?

like image 473
Ethan Avatar asked May 14 '10 00:05

Ethan


People also ask

How do I drop a column in Rails?

The change method can be used to drop a column in Rails 4 applications, but should not be used in Rails 3. I updated my answer accordingly. You can also use remove_column :table_name, :column_name, :type, :options within the change method, since if you specify the type reverting the migration is possible.


1 Answers

remove_column :table_name, :column_name 

For instance:

remove_column :users, :hobby 

would remove the hobby Column from the users table.

like image 69
Nick Hammond Avatar answered Sep 19 '22 17:09

Nick Hammond