Cameron Bass Cameron Bass - 7 months ago 85
Ruby Question

Deleting table from schema - Rails

I want to delete a table in my schema. I created the database when I first started the project and want the table removed. What is the best way of doing this?

I tried

rails g migration drop table :installs
but that just creates a empty migration?


create_table "installs", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false

add_index "installs", ["email"], name: "index_installs_on_email", unique: true
add_index "installs", ["reset_password_token"], name: "index_installs_on_reset_password_token", unique: true


If you create an empty migration by running:
rails g migration DropInstalls
rails generate migration DropInstalls

You can then add this into that empty migration:

class DropInstalls < ActiveRecord::Migration
  def change
    drop_table :installs

Then run rake db:migrate in the command line which should remove the Installs table

See the Active Record Migrations documentation for more details.