5

我是rake新手,我正在尝试找到自动化某些任务的方法。所以我写了我的第一个rake 任务并且失败了:

namespace :app do
  desc "Leaves application like new"
  task :reset => :environment do
    Rake::Task['db:drop:all'].invoke
    Rake::Task['db:create:all'].invoke
    Rake::Task['db:migrate'].invoke
    Rake::Task['db:seed'].invoke
  end
end

我想知道为什么这不起作用。调用后:

rake app:reset

一切运行良好,我可以在屏幕上看到迁移消息,如下所示:

==  CreateGalerias: migrating =================================================
-- create_table(:galerias)
NOTICE:  CREATE TABLE will create implicit sequence "galerias_id_seq" for serial column "galerias.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "galerias_pkey" for table "galerias"
   -> 0.1191s
==  CreateGalerias: migrated (0.1194s) ========================================

但是,最后我收到这条消息:

You have 11 pending migrations:
  20110704052637 CreatePersonas
  20110709100632 CreateOrganizaciones
  20110709100646 CreateEventos
  20110816102451 CreateMembresias
  20110816155851 CreateCelebraciones
  20110822135820 ActsAsTaggableOnMigration
  20120410063100 CreateDocumentos
  20120507200516 CreateUsuarios
  20120515214226 ActivaUnnaccent
  20120516091228 CreateGalerias
  20120517004708 SetupHstore
Run `rake db:migrate` to update your database then try again.

不是刚迁移数据库吗?为什么抱怨它?

4

1 回答 1

2

请记住 db:drop:all 和 db:create:all 可在所有环境中运行,而 db:migrate 和 db:seed 则不能,因此您可能正在一个非预期的环境中进行迁移。尝试将 db:drop:all 更改为 db:drop 并将 db:create:all 更改为 db:create,然后运行指定特定环境的任务,例如:

rake RAILS_ENV=production app:reset
于 2012-06-26T14:51:03.320 回答