Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drop Table, Model, Migration in Rails

Dropping Migration Table, Models, Controller

Command Line

1. Drop Table/Migration

rails generate migration DropTablename

A file will be created, in the db > migrate folder, make sure it looks like:

class DropUsers < ActiveRecord::Migration
  def change
    drop_table :users
  end
end

2. Drop Model

rails d model user

3. Drop Controller

rails d controller users

4. Re-Migrate

be rake db:migrate
@Dmoment

This comment has been minimized.

Copy link

@Dmoment Dmoment commented Jan 6, 2020

Thanks, It was helpful.

@C-Jay-Kumar

This comment has been minimized.

Copy link

@C-Jay-Kumar C-Jay-Kumar commented Feb 21, 2020

Thank you. Concise and helpful.

@ayoa77

This comment has been minimized.

Copy link

@ayoa77 ayoa77 commented Oct 21, 2020

Ha perfect! Thanks for this. I find myself looking this type of stuff up constantly, this was exactly what I needed 👍

@quarkgluant

This comment has been minimized.

Copy link

@quarkgluant quarkgluant commented Nov 27, 2020

Thanks a lot !
But be careful your migration will not be reversible.
For this, you need to add something like this :

class DropEventExport < ActiveRecord::Migration[6.0]
  def change
    drop_table :event_exports do |t|
      t.boolean "global", default: false
      t.string "file_file_name"
      t.string "file_content_type"
      t.integer "file_file_size"
      t.datetime "file_updated_at"

      t.timestamps null: false
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment