gpt4 book ai didi

ruby-on-rails - rake 数据库 :seed generates ArgumentError: missing keywords: from, 到

转载 作者:行者123 更新时间:2023-12-05 08:51:47 26 4
gpt4 key购买 nike

我得到了一个数据库来测试我的代码。当我运行 rake db:seed 为数据库设置种子时,出现以下错误。

我预计控制台是空白的:这意味着数据已经播种。

错误:

[19:19:41] (master) simple-partials-lab-noukod-000
// ♥ rake db:seed
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-4.2.11.1/lib/active_support/core_ext/object/duplicable.rb:111: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
rake aborted!
ArgumentError: missing keywords: from, to
/usr/local/rvm/gems/ruby-2.6.1/gems/faker-2.2.1/lib/faker/default/date.rb:6:in `between'
/home/considerate-transform-1229/simple-partials-lab-noukod-000/db/seeds.rb:9:in `block in <top (required)>'
/home/considerate-transform-1229/simple-partials-lab-noukod-000/db/seeds.rb:8:in `times'
/home/considerate-transform-1229/simple-partials-lab-noukod-000/db/seeds.rb:8:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:268:in `load'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:268:in `block in load'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/rvm/gems/ruby-2.6.1/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:268:in `load'
/usr/local/rvm/gems/ruby-2.6.1/gems/railties-4.2.11.1/lib/rails/engine.rb:547:in `load_seed'
/usr/local/rvm/gems/ruby-2.6.1/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:253:in `load_seed'
/usr/local/rvm/gems/ruby-2.6.1/gems/activerecord-4.2.11.1/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.6.1/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

最佳答案

看起来你正在使用旧语法的 Faker。它最近更改为需要关键字参数而不是位置参数。

您需要遵循更新后的语法:

Faker::Date.between(from: 2.days.ago, to: Date.today) #=> "Wed, 24 Sep 2014"

注意指定参数的关键字 from:to:。参数的顺序并不重要,相反的顺序也一样:

Faker::Date.between(to: Date.today, from: 2.days.ago) #=> "Wed, 24 Sep 2014"

他们的文档中提供了其他信息:https://github.com/faker-ruby/faker/blob/master/doc/default/date.md

关于ruby-on-rails - rake 数据库 :seed generates ArgumentError: missing keywords: from, 到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58633069/

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