How to drop a table in Rails 5

July 18, 2019
I'm making an alternative to DevTools. Click here to check it out.

To drop a table in Rails 5, run the following migration. Change Posts to the name of your table, and make sure it’s plural.

rails g migration DropPosts

Open up the migration you’ve just generated inside db/migrate, and change it to the following:

class DropPosts < ActiveRecord::Migration[5.2] # change `Posts`
  def change
    drop_table :posts # change `posts`

Then run rails db:migrate. Your table should now be dropped.