2016-06-22 31 views
3

我以前發佈過這個問題,但我沒有得到任何解決我的問題的答案。因此,我正在重新發布這個問題。不能在生產中使用heroku種子數據

我正在使用heroku部署我的導軌應用程序。我試圖通過運行命令heroku run rake db:seed.在生產中播種一些數據。但是,該命令不起作用。我無法在生產中播種文件。下面給出了seeds.rb文件。

#This file should contain all the record creation needed to seed the database with its default values. 
#The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 

#Examples: 

    #cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 
    #Mayor.create(name: 'Emanuel', city: cities.first) 

#end 


    5.times do    
    Scoreboard.create!(name_of_scoreboard: "scoreboard_abc", 
         name_of_organization: "abcdef", 
         name_of_activity: "ghijklmn", 
         user_id: 1, 
         states: "state", 
         country: "state", 
         cities: "state") 
    end 

$ Heroku的運行耙分貝:種子 運行耙分貝:種子上⬢應用...起​​來,run.4751 的ActiveRecord :: SchemaMigration負載(2.0ms)選擇 「schema_migrations」 * FROM「schema_migrations 「

我運行了heroku restart但對象沒有播種到生產數據庫中。我試圖在開發中播種這個文件,並且它完美地工作。我不確定有什麼問題。

heroku日誌-t文件在下面給出。

2016-06-22T00:50:58.882699+00:00 heroku[api]: Starting process with command `bundle exec rake db:seed` by *******@gmail.com 
2016-06-22T00:51:07.986301+00:00 heroku[run.1041]: Awaiting client 
2016-06-22T00:51:08.026539+00:00 heroku[run.1041]: Starting process with command `bundle exec rake db:seed` 
2016-06-22T00:51:08.157630+00:00 heroku[run.1041]: State changed from starting to up 
2016-06-22T00:51:12.891248+00:00 heroku[run.1041]: State changed from up to complete 
2016-06-22T00:51:12.881329+00:00 heroku[run.1041]: Process exited with status 0 

我有database.yml文件和seeds.rb文件作爲gitignore的一部分。我不確定這是否是問題的原因。我很確定它沒有。

+0

你看過'heroku logs --tail'來找到你的種子的錯誤嗎? –

+0

@maxpleaner,我沒有,但我現在看看它,併發布日誌文件。 – kpaul

+0

@maxpleaner,我已經發布了來自heroku的實時日誌文件。不知道發生了什麼,但發佈的請求沒有經過 – kpaul

回答

1

seeds.rb應該在存儲庫中以便爲rails播種它。如果沒有seeds.rb,rails不會抱怨該文件丟失,而只是完成rake db:seed任務,並且沒有任何錯誤。

所以一定要確保你從.gitignore刪除seeds.rb,它git add --force db/seeds.rbgit push添加到git它的存儲庫。