16

Я попытался запустить:Как вернуть все миграции сразу в Ruby on Rails 3?

rake db:migrate VERSION=0 

Он отменяет все миграции кроме последнего.

Затем я попытался запустить:

rake db:migrate:down VERSION=<timestamp_of_last_migration> 

, но он не вернется ни. Зачем ?

Есть ли команда, которая запускает все методы down сразу?

+1

Поиск того, как откатить все миграции, я наткнулся на этот вопрос. Я просто хочу сказать, что в настоящее время (Rails 3.2.9) `rake db: migrate VERSION = 0`, кажется, работает нормально, возвращая все миграции. – janosrusiczki 2013-02-02 21:30:34

+0

Этот вопрос кажется неправильным или устаревшим. `rake db: migrate VERSION = 0` откатывает каждую миграцию **, включая первую **. – 2015-08-27 15:08:37

ответ

11

Если ваша база данных связана только с этим проектом, и вы пытаетесь отменить все в своих миграциях, я бы просто сбросил базу данных, а затем запустил rake db: create.

Затем у вас есть пустая база данных, готовая к работе.

Или есть еще одна причина, по которой вы пытаетесь запустить сценарии вниз?

+0

Вот что я сделал наконец. Но, я все еще удивляюсь, почему вышеприведенные команды не работают ... – 2010-12-09 06:07:35

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 
2

попробовать:

rake db:migrate:down VERSION=<timestamp_of_first_migration> 

это будет работать self.down для первого переноса, по существу, вытирая все из. по крайней мере, это просто для меня!

 Смежные вопросы

  • Нет связанных вопросов^_^