我是OneMonth学习条纹支付的初学者。现在,我正在学习如何创建产品表并为数据库设定种子。到目前为止,一切顺利,直到我在运行rake db:seed
后遇到问题 Davids-MBP-2:one_month_stripe_payments DKP $ rake db:seed
耙子流产了!
ActiveRecord :: RecordInvalid:验证失败:已经收到电子邮件
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/validations.rb:79:in raise_record_invalid'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/validations.rb:43:in
save!'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:29:in save!'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:291:in
阻止保存!'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:351:in block in with_transaction_returning_status'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
阻止事务'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in within_new_transaction'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
transaction'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in transaction'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:348:in
with_transaction_returning_status'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:291:in save!'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/persistence.rb:51:in
创建!'
/Users/DKP/Desktop/one_month/one_month_stripe_payments/db/seeds.rb:8:in <top (required)>'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in
load'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in block in load'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in
load_dependency'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in load'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/railties-4.2.5/lib/rails/engine.rb:547:in
load_seed'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:250:in load_seed'
/Users/DKP/.rvm/gems/ruby-2.3.0@global/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:183:in
块(2级)in “
/Users/DKP/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in eval'
/Users/DKP/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in
'
任务:TOP =&gt; DB:种子
(通过使用--trace运行任务查看完整跟踪)
我尝试过rake db:reset,然后rake:db migrate,然后再次rake db:seed。但我仍然有同样的错误。
有人可以帮我解决这个问题吗?我感觉卡住了,我不知道该怎么做。
非常感谢!
答案 0 :(得分:3)
&#39;电子邮件已被拍摄&#39;表示您有一条记录,其中已存在相同的电子邮件。
执行Rails控制台并检查记录是否存在。 如果没有,请做rake db:drop - &gt; rake db:create - &gt; rake db:migrate - &gt; rake db:seed。这将解决您的问题。
答案 1 :(得分:2)
执行rake db:reset
时,rake db:drop
- &gt; rake db:create
- &gt; rake db:migrate
- &gt; rake db:seed
。
您不需要再次rake db:seed
。
您可以通过rails c
检查您的控制台,看看您是否已将数据置于种子内部。 Product.all