2012-01-09 33 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(從而避免了復位時將使用該更新版本等待遷移錯誤)。