Ruby-on-rails 从架构中删除表 - Rails
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38711156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deleting table from schema - Rails
提问by Bitwise
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 :installsbut that just creates a empty migration?
我试过了,rails g migration drop table :installs但这只会创建一个空的迁移?
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
回答by Luka Kerr
If you create an empty migration by running:
rails g migration DropInstalls
or:rails generate migration DropInstalls
如果您通过运行创建空迁移:
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
end
end
Then run rake db:migratein the command line which should remove the Installs table
然后rake db:migrate在应该删除安装表的命令行中运行

