RoR:rake db:种子错误

时间:2015-09-02 22:10:32

标签: ruby-on-rails rake

这里最有可能是一个令人注意的问题,但不管怎样,我都会陷入困境。我试图在数据库中设置一些信息,而rake db:seed错误出现在我身上,我无法弄清楚原因。

我的错误讯息:

[tomos@Helix swipeApp]$ rake db:seed --trace
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
rake aborted!
ArgumentError: wrong number of arguments (0 for 1..3)
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activerecord-            4.2.4/lib/active_record/associations.rb:1258:in `has_many'
/home/tomos/Dropbox/EventsApp/WebApp/swipeApp/app/models/tag.rb:4:in `<class:Tag>'
/home/tomos/Dropbox/EventsApp/WebApp/swipeApp/app/models/tag.rb:1:in `<top (required)>'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:457:in `load'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:457:in `block in load_file'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:647:in `new_constants_in'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:456:in `load_file'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:354:in `require_or_load'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:494:in `load_missing_constant'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:184:in `const_missing'
/home/tomos/Dropbox/EventsApp/WebApp/swipeApp/db/seeds.rb:22:in `<top (required)>'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `block in load'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/engine.rb:547:in `load_seed'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/home/tomos/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:183:in `block (2 levels) in <top (required)>'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/tomos/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/tomos/.rvm/rubies/ruby-2.2.1/bin/rake:33:in `<main>'
Tasks: TOP => db:seed

分贝/迁移/ 20150902195742_create_tags.rb:

class CreateTags < ActiveRecord::Migration
  def change
    create_table :tags do |t|
        t.string :title
        t.string :image
      t.timestamps null: false
    end
  end
end

分贝/迁移/ 20150902195921_create_events.rb:

class CreateEvents < ActiveRecord::Migration
  def change
    create_table :events do |t|
        t.string :name
        t.string :image
        t.string :description
        t.references :tag
      t.timestamps null: false
    end
  end
end

这是app / models / tag.rb:

class Tag < ActiveRecord::Base
        ActiveRecord::Base
                has_many
        :destinations
end

最后我的db / seeds.rb:

t1 = Tag.create(title: "Tag 1", image: File.new("image/to/path.jpg"))
Event.create(name: "Event 1", description: "Event 1 is gonna blow ur mind.", image: File.new("image/to/path.jpg"), tag_id: t1.id)
Event.create(name: "Event 2", description: "Holy shit this is incredibles.", image: File.new("image/to/path.jpg"), tag_id: t1.id)
Event.create(name: "Event 3", description: "Yummy tasty event 3 description here", image: File.new("image/to/path.jpg"), tag_id: t1.id)
t2 = Tag.create(title: "Tag 1", image: File.new("image/to/path.jpg"))
Event.create(name: "Event 1", description: "Event 1 is gonna blow ur mind.", image: File.new("image/to/path.jpg"), tag_id: t2.id)
Event.create(name: "Event 2", description: "Holy shit this is incredibles.", image: File.new("image/to/path.jpg"), tag_id: t2.id)
Event.create(name: "Event 3", description: "Yummy tasty event 3 description here", image: File.new("image/to/path.jpg"), tag_id: t2.id)
t3 = Tag.create(title: "Tag 1", image: File.new("image/to/path.jpg"))
Event.create(name: "Event 1", description: "Event 1 is gonna blow ur mind.", image: File.new("image/to/path.jpg"), tag_id: t3.id)
Event.create(name: "Event 2", description: "Holy shit this is incredibles.", image: File.new("image/to/path.jpg"), tag_id: t3.id)
Event.create(name: "Event 3", description: "Yummy tasty event 3   description here", image: File.new("image/to/path.jpg"), tag_id: t3.id)

如果我遗漏了任何重要信息,请告诉我。非常感谢!

1 个答案:

答案 0 :(得分:1)

检查错误消息,尤其是第4行:

ArgumentError: wrong number of arguments (0 for 1..3)
# some message here
/home/tomos/Dropbox/EventsApp/WebApp/swipeApp/app/models/tag.rb:4:in `<class:Tag>'
# some message here