2016-03-02 80 views
-1

我是一位在Rails 4.2.4中構建條帶支付處理系統的新開發人員。Heroku run rake db:種子錯誤

我的應用程序在本地完美運行,但是當我將其推送到Heroku時,在運行rake db:seed後出現此錯誤。

雖然之前運行良好,但我現在還是無法使應用程序在生產級別打開。

這是在終端的錯誤:

rake aborted! 
    ActiveRecord::RecordInvalid: Validation failed: Email has already been taken 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/validations.rb:79:in `raise_record_invalid' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/validations.rb:43:in `save!' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/attribute_methods/dirty.rb:29:in `save!' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:291:in `block in save!' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:220:in `transaction' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:348:in `with_transaction_returning_status' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/transactions.rb:291:in `save!' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/persistence.rb:51:in `create!' 
    /app/db/seeds.rb:9:in `<top (required)>' 
    /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load' 
    /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `block in load' 
    /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency' 
    /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load' 
    /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:547:in `load_seed' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:250:in `load_seed' 
    /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:183:in `block (2 levels) in <top (required)>' 
    Tasks: TOP => db:seed 

這是seeds.rb:

AdminUser.create!(email: '[email protected]', password: 'password', password_confirmation: 'password') 

placenta_wash = Product.create(title: "Placenta Wash", 
subtitle: "Nippon Beauty", author: "Chris Dorman", 
length: "30 minutes", author_image_name: "teacher-image.jpg", 
price: "4.99", sku: "GROHACK1", download_url: "https://s3.amazonaws.com/one-month-stripe-payments-dorman/CV.pdf", 
details: "You'll get one video", description: %{<p>A growth hacker is a rare combination: someone with the right marketing and technical skills who can come up with clever marketing hacks and also track their results.</p> 

<p>In this talk, Mattan Griffel introduces you to the concept of Growth Hacking and shares his favorite tips for getting started as a growth hacker.</p> 
<p><strong>What You'll Learn</strong></p> 
<ul class="no-indent"> 
<li>What is a growth hacker?</li> 
<li>The 5 stages of the user lifecycle</li> 
<li>How to apply the Lean Marketing Framework</li> 
<li>Resources and tools you'll need to know</li> 
</ul>}, 
author_description: %{ <p>Hey, I'm Mattan Griffel, co-founder of the Y Combinator backed <a href="http://www.onemonth.com" target="_blank">One Month</a> where I teach the best selling One Month Rails and One Month Growth Hacking.</p> 
<p>Why take my class? In the past I've advised companies like Pepsico, Bloomberg, GM, NYSE, and JPMorgan on growth hacking best practices. I've also spoken at New York University, Cooper Union and First Round Capital. My goal is to help you and other entrepreneurs rapidly grow your business. 
</p> 
<p>Follow me on Twitter <a href="https://twitter.com/mattangriffel" target="_blank">@mattangriffel</a></p>}) 

growth_hacking_monthly = Product.create(title: "Growth Hacking Monthly", 
subtitle: "Ongoing Course", author: "Chris Dorman", 
length: "6 months", author_image_name: "teacher-image.jpg", 
price: "4.99", sku: "GROHACK2", download_url: "https://s3.amazonaws.com/one-month-stripe-payments/Peter+Bell+Resume.pdf", 
details: "We'll charge you monthly for unlimited access to our mentoring team", description: %{<p>A growth hacker is a rare combination: someone with the right marketing and technical skills who can come up with clever marketing hacks and also track their results.</p> 

<p>In this series, Mattan Griffel introduces you to the concept of Growth Hacking and shares his favorite tips for getting started as a growth hacker.</p> 
<p><strong>What You'll Learn</strong></p> 
<ul class="no-indent"> 
<li>What is a growth hacker?</li> 
<li>The 5 stages of the user lifecycle</li> 
<li>How to apply the Lean Marketing Framework</li> 
<li>Resources and tools you'll need to know</li> 
</ul>}, 
author_description: %{ <p>Hey, I'm Mattan Griffel, co-founder of the Y Combinator backed <a href="http://www.onemonth.com" target="_blank">One Month</a> where I teach the best selling One Month Rails and One Month Growth Hacking.</p> 
<p>Why take my class? In the past I've advised companies like Pepsico, Bloomberg, GM, NYSE, and JPMorgan on growth hacking best practices. I've also spoken at New York University, Cooper Union and First Round Capital. My goal is to help you and other entrepreneurs rapidly grow your business. 
</p> 
<p>Follow me on Twitter <a href="https://twitter.com/mattangriffel" target="_blank">@mattangriffel</a></p>}) 
+0

您是第一次運行'heroku run rake db:seed'還是之前跑過它? – harshs08

+0

你可以發佈你的seeds.rb文件嗎? – M00B

+0

你想要我的種子文件張貼爲JPG還是塊引用。謝謝 –

回答

1

你看到這一點,因爲你有你的管理用戶模式的電子郵件領域的獨特性驗證。由於電子郵件地址爲not being unique,因此在您的seends.rb行中創建的記錄無效,因此種子失敗。這個問題不是Heroku特有的 - 如果你在本地運行rake db:seed,它應該以同樣的方式失敗,連續兩次。

您可能會嘗試在您的seeds.rb文件中添加類似AdminUser.destroy_all的東西(或者如果不是用戶,則爲模型名稱)。我會非常小心,雖然因爲你不想刪除生產數據。

更好的是,只需將unless AdminUser.find_by(email: '[email protected]')添加到種子文件第一行的末尾即可。

如果您只是想將一些數據添加到您的應用程序,您可能想要查看創建填充任務。有一個RailsCast on this subject

+0

im我不明白你的說明。它在本地完美工作,我無法在heroku中加載頁面 –

+0

對不起,如果我不清楚。你的種子失敗了,因爲在你的系統中已經有一個AdminUser和'[email protected]'。你可以做很多事情來解決這個問題:最簡單的辦法可能是在你的種子文件的第1行創建AdminUser,除非AdminUser.find_by(email:'[email protected]')' – M00B

+0

種子沒有在本地失敗,雖然 –

相關問題