首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Ruby on Rails 3中一次恢复所有迁移?

如何在Ruby on Rails 3中一次恢复所有迁移?
EN

Stack Overflow用户
提问于 2010-12-09 13:42:43
回答 4查看 8.6K关注 0票数 16

我试着跑:

代码语言:javascript
复制
rake db:migrate VERSION=0

它会恢复除最后一个之外的所有迁移

然后我试着跑:

代码语言:javascript
复制
rake db:migrate:down VERSION=<timestamp_of_last_migration>

但它也没有恢复。为什么?

有没有一个命令可以一次运行所有的down方法?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-12-09 13:55:59

如果您的数据库只与此项目相关,并且您正在尝试撤消迁移中的所有操作,那么我只需删除该数据库,然后运行rake :create。

然后你就有了一个空的数据库了。

或者,您尝试运行向下脚本还有其他原因吗?

票数 11
EN

Stack Overflow用户

发布于 2010-12-10 01:27:27

你可以看看这张清单。

也许这能帮到你

代码语言:javascript
复制
rake db:create[:all]: If :all not specified then create the database defined in config/database.yml for the current RAILS_ENV. If :all is specified then create all of the databases defined in config/database.yml.
rake db:fixtures:load: Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y
rake db:migrate [VERSION=n]: Migrate the database through scripts in db/migrate. Target specific version with VERSION=n
rake db:migrate:redo [STEP=n]: (2.0.2) Revert the database by rolling back "STEP" number of VERSIONS and re-applying migrations.
rake db:migrate:reset: (2.0.2) Drop the database, create it and then re-apply all migrations. The considerations outlined in the note to rake db:create apply.
rake db:reset: Drop and re-create database using db/schema.rb. The considerations outlined in the note to rake db:create apply.
rake db:rollback [STEP=N]: (2.0.2) Revert migration 1 or n STEPs back.
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:sessions:clear: Clear the sessions table
rake db:sessions:create: Creates a sessions table for use with CGI::Session::ActiveRecordStore
rake db:structure:dump: Dump the database structure to a SQL file
rake db:test:clone: Recreate the test database from the current environment's database schema
rake db:test:clone_structure: Recreate the test databases from the development structure
rake db:test:prepare: Prepare the test database and load the schema
rake db:test:purge: Empty the test database
票数 10
EN

Stack Overflow用户

发布于 2013-09-26 19:16:59

还有另一种方法:

代码语言:javascript
复制
rake db:rollback STEP=100

这将恢复最近100次迁移

摘自http://guides.rubyonrails.org/migrations.html#rolling-back

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4395238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档