Generate a migration to remove a column such that if it is migrated (rake db:migrate
), it should drop the column. And it should add column back if this migration is rollbacked (rake db:rollback
).
The syntax:
remove_column :table_name, :column_name, :type
Removes column, also adds column back if migration is rollbacked.
Example:
remove_column :users, :last_name, :string
Note: If you skip the data_type, the migration will remove the column successfully but if you rollback the migration it will throw an error.