16

私は実行しようとしました:

rake db:migrate VERSION=0

最後の移行を除くすべての移行を元に戻します。

次に、実行しようとしました:

rake db:migrate:down VERSION=<timestamp_of_last_migration>

しかし、それも元に戻りませんでした。なんで ?

downすべてのメソッドを一度に実行するコマンドはありますか?

4

4 に答える 4

11

データベースがこのプロジェクトにのみ関連していて、移行のすべてを元に戻そうとしている場合は、データベースを削除してから、rake db:createを実行します。

これで、空のデータベースを使用できるようになります。

または、ダウンスクリプトを実行しようとしている別の理由がありますか?

于 2010-12-09T05:55:58.573 に答える
10

このリストを確認できます。

多分これはあなたを助けることができます

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
于 2010-12-09T17:27:26.953 に答える
7

別の方法があります:

rake db:rollback STEP=100

これにより、最後の 100 件の移行が元に戻ります

http://guides.rubyonrails.org/migrations.html#rolling-backから取得

于 2013-09-26T11:16:59.363 に答える
2

試す:

rake db:migrate:down VERSION=<timestamp_of_first_migration>

これにより、最初の移行で self.down が実行され、基本的にすべてが消去されます。少なくとも、それは私のためにやっただけです!

于 2011-01-31T07:34:00.473 に答える