Removing a Column in a Database Using Migrations in Rails
Learn how to delete a column from a database using migration in a Ruby on Rails application.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

For demonstration purposes I created a new column in the database projects and named it division.

large

To delete this column, go to your console and type,

rails g migration remove_division_from_projects division:string

large

Now, go to the file 201510300010018_remove_division_from_projects.rb

This is what the file looks like:

large

The code is pretty basic and you're probably getting used to seeing the syntax. Inside the change method, there is a call to remove_column and the parameters are the name of the table, name of the column and the data type of the column.

Next, go to the console again and type rake db:migrate and you'll see that the schema file has reflected the change. You'll see that the column division does not exist anymore.

large