database 在 Rails 中销毁/删除数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/17649686/
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
Destroy/Remove database in Rails
提问by fearofawhackplanet
Is it possible to completely remove the database and all migration records etc from an existing application so I can redesign the database from scratch?
是否可以从现有应用程序中完全删除数据库和所有迁移记录等,以便我可以从头开始重新设计数据库?
回答by Paulo Fidalgo
By issuing rake -Tyou have the following database tasks:
通过发出rake -T您有以下数据库任务:
rake db:create          # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop            # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load   # Load fixtures into the current environment's database
rake db:migrate         # Migrate the database (options: VERSION=x, VERBOSE=false)
rake db:migrate:status  # Display status of migrations
rake db:rollback        # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:dump     # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load     # Load a schema.rb file into the database
rake db:seed            # Load the seed data from db/seeds.rb
rake db:setup           # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
rake db:structure:dump  # Dump the database structure to db/structure.sql
rake db:version         # Retrieves the current schema version number
So to issue bundle exec rake db:drop:alland if you want to remove all the migrations, and assuming you want to remove only the migrations, delete them and write new ones. 
因此bundle exec rake db:drop:all,如果您想删除所有迁移,并假设您只想删除迁移,请删除它们并编写新的迁移。
If you want to change your models too, use rails d model.
如果您也想更改模型,请使用rails d model.
回答by stephenmurdoch
This will get rid of the db:
这将摆脱数据库:
rake db:drop 
And for each migration that you have:
对于您拥有的每个迁移:
rails d migration migration_name
回答by Dheer
Yes, Its possible to remove the database and migration.
是的,可以删除数据库和迁移。
rake db:drop
rake db:rollback
rails d migration 'migration name'
rake db:create
rake db:migrate
rake db:seed
rake db:test:prepare

