16

ich versuchte zu laufen:Wie können alle Migrationen auf einmal in Ruby on Rails 3 zurückgesetzt werden?

rake db:migrate VERSION=0 

Es kehrt alle Migrationen mit Ausnahme des letzten.

Dann habe ich versucht zu laufen:

rake db:migrate:down VERSION=<timestamp_of_last_migration> 

aber es entweder nicht zurück. Warum ?

Gibt es einen Befehl, der alle down Methoden auf einmal ausführt?

+1

Suche, wie alle Migrationen rückgängig zu machen, stieß ich auf diese Frage. Ich möchte nur sagen, dass heutzutage (Rails 3.2.9) 'rake db: migrate VERSION = 0' gut zu funktionieren scheint und alle Migrationen rückgängig gemacht werden. – janosrusiczki

+0

Diese Frage scheint falsch oder veraltet zu sein. 'rake db: Migriere VERSION = 0' Rollbacks bei jeder Migration, ** einschließlich des ersten **. –

Antwort

11

Wenn Ihre Datenbank nur zu diesem Projekt gehört und Sie versuchen, alles in Ihren Migrationen rückgängig zu machen, würde ich einfach die Datenbank löschen und dann rake db: create ausführen.

Dann haben Sie eine leere Datenbank bereit zu gehen.

Oder gibt es einen anderen Grund, warum Sie versuchen, die Down-Scripts auszuführen?

+0

Das habe ich schließlich getan. Aber ich frage mich immer noch, warum die obigen Befehle nicht funktioniert haben ... –

+2

Trolled durch die Schienen Rake-Aufgaben, und es sieht aus wie Rake db: drop db: create ist die einzige echte Option. Ich würde sagen, der Grund, warum Migrationen dich nicht zu nichts führen lassen, ist, dass sie dazu bestimmt waren, INNERHALB der Migrationen herumzureisen. Nicht zurück auf Null setzen. – boymc

10

Sie könnten diese Liste überprüfen.

könnte man vielleicht

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 
2

try helfen:

rake db:migrate:down VERSION=<timestamp_of_first_migration> 

dies die self.down für die erste Migration laufen, im Wesentlichen alles auszulöschen. zumindest hat es nur für mich getan!