Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在RubyonRails3中一次恢复所有迁移?_Ruby On Rails_Ruby On Rails 3_Migration_Rake_Database Migration - Fatal编程技术网

Ruby on rails 如何在RubyonRails3中一次恢复所有迁移?

Ruby on rails 如何在RubyonRails3中一次恢复所有迁移?,ruby-on-rails,ruby-on-rails-3,migration,rake,database-migration,Ruby On Rails,Ruby On Rails 3,Migration,Rake,Database Migration,我试着跑: rake db:migrate VERSION=0 它还原除最后一次迁移以外的所有迁移 然后我试着跑: rake db:migrate:down VERSION=<timestamp_of_last_migration> rakedb:migrate:down版本= 但它也没有恢复。为什么? 是否有一个命令可以同时运行所有的down方法?如果您的数据库仅与此项目相关,并且您试图撤消迁移中的所有操作,我只需删除数据库,然后运行rake db:create 然后您就有了

我试着跑:

rake db:migrate VERSION=0
它还原除最后一次迁移以外的所有迁移

然后我试着跑:

rake db:migrate:down VERSION=<timestamp_of_last_migration>
rakedb:migrate:down版本=
但它也没有恢复。为什么?


是否有一个命令可以同时运行所有的
down
方法?

如果您的数据库仅与此项目相关,并且您试图撤消迁移中的所有操作,我只需删除数据库,然后运行rake db:create

然后您就有了一个空的数据库准备就绪


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

您可以查看此列表

也许这对你有帮助

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
尝试:

rakedb:migrate:down版本=
这将为您的第一次迁移运行self.down,基本上清除所有内容。至少对我来说是这样

还有另一种方法:

rake db:rollback STEP=100
这将恢复最后100次迁移


摘自

这就是我最后所做的。但是,我仍然想知道为什么上面的命令不起作用……在rails rake任务中,rake db:drop db:create似乎是唯一的实际选项。我要说的是,迁移不会让您一事无成,因为它们是为了在迁移中移动。没有重置回零。在搜索如何回滚所有迁移时,我偶然发现了这个问题。我只想说,现在(Rails 3.2.9)
rake db:migrate VERSION=0
似乎运行良好,恢复了所有迁移。这个问题似乎是错误的或过时的
rake db:migrate VERSION=0
回滚每次迁移,包括第一次迁移。
rake db:rollback STEP=100