2012-01-09 56 views
0

我有一个引导任务,我打算有db:resetdb:migrate作为先决条件。我定义它是这样的:为什么不将db:migrate作为先决条件进行调用?

task :bootstrap => [:environment,:"db:reset",:"db:migrate"] do ... 

当我运行它,我得到以下的输出:

** Invoke bs:bootstrap (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:reset (first_time) 
** Invoke db:drop (first_time) 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
** Execute db:drop 
** Invoke db:setup (first_time) 
** Invoke db:create (first_time) 
** Invoke db:load_config 
** Execute db:create 
** Invoke db:schema:load (first_time) 
** Invoke environment 
** Execute db:schema:load 
-- create_table("projects", {:force=>true}) 
    -> 0.0770s 
-- create_table("users", {:force=>true}) 
    -> 0.1110s 
... 
** Invoke db:seed (first_time) 
** Invoke db:abort_if_pending_migrations (first_time) 
** Invoke environment 
** Execute db:abort_if_pending_migrations 
You have 1 pending migrations: 
    20120109172252 CreateObjectives 
Run "rake db:migrate" to update your database then try again. 

为什么不db:migrate被调用,因为它的上市为前提?

+0

是否确定db:reset之前列出的数据不需要迁移挂起,并且在db到达之前失败:migrate? – 2012-01-09 17:37:49

+0

我应该如何确保数据库中没有任何东西?我希望它在启动之前完全清空。 – Geo 2012-01-09 17:39:04

回答

2

它看起来像db:reset正在中止,因为你有未决的迁移。由于db:reset将使用db:schema:load来使用你的db/schema.rb文件来重置数据库,所以你不应该真的需要运行迁移。

你可以做什么,而不是放在分贝:迁移分贝:复位 - 这将运行迁移,更新schema.rb文件,以便DB:重置DB(从而避免了复位时将使用该更新版本等待迁移错误)。