gpt4 book ai didi

ruby-on-rails - Rake db:种子 rake 中止! ActiveRecord::RecordInvalid: 验证失败:电子邮件已经被占用

转载 作者:行者123 更新时间:2023-12-01 10:36:09 25 4
gpt4 key购买 nike

我是 OneMonth 的 Rails 初学者学习 Stripe 支付。现在,我正在学习如何创建产品表并为数据库设置种子。到目前为止一切都很顺利,直到我在运行 rake db:seed 后遇到问题

Davids-MBP-2:one_month_stripe_payments DKP$ 佣金 db:seed
rake 中止!
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
节省!'
/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
交易'
/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
加载'
/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
负载依赖'
/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
加载种子'
/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 级)
/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 => db:seed
(通过使用 --trace 运行任务查看完整跟踪)

我试过 rake db: reset,然后 rake:db migrate,然后再次 rake db: seed。但我仍然有同样的错误。

有人可以帮我解决这个问题吗?我感觉被卡住了,我不知道该怎么办。

非常感谢!

最佳答案

当您这样做时rake db:reset , rails 的作用是 rake db:drop -> rake db:create -> rake db:migrate -> rake db:seed .

您不需要 rake db:seed再次。

您可以通过执行 rails c 来检查您的控制台看看你的种子数据是否已经在里面。 Product.all

关于ruby-on-rails - Rake db:种子 rake 中止! ActiveRecord::RecordInvalid: 验证失败:电子邮件已经被占用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35110196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com