我是 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.
它刚刚迁移了数据库吗?为什么抱怨它?
答案 0 :(得分: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