15

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?

Schema:

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
  end

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
Luka Kerr
  • 4,161
  • 7
  • 39
  • 50
Bitwise
  • 8,021
  • 22
  • 70
  • 161
  • 2
    Possible duplicate of [Rails DB Migration - How To Drop a Table?](http://stackoverflow.com/questions/4020131/rails-db-migration-how-to-drop-a-table) – Paul Fioravanti Aug 02 '16 at 03:11
  • I'd say that it isn't quite a duplicate in that this is a question about the schema (even if that isn't what should be edited). – jonlink Feb 04 '17 at 16:10

1 Answers1

51

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

You can then add this into that empty migration:

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

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

Note: db/schema.rb is an autogenerated file. To alter the db structure, you should use the migrations instead of attempting to edit the schema file.

saurabh
  • 6,687
  • 7
  • 42
  • 63
Luka Kerr
  • 4,161
  • 7
  • 39
  • 50
  • 3
    This answer would be more complete if it pointed out that the schema is an autogenerated file and therefore the wrong thing to be looking at. – jonlink Feb 04 '17 at 16:12