rake db:seed - ArgumentError::dependent选项必须是[:destroy,:delete_all,:nullify之一

时间:2017-02-09 21:28:19

标签: ruby-on-rails ruby ruby-on-rails-4 rake

所以我正在尝试为我的数据库播种,我正在接受 这个奇怪的论证错误?有什么想法吗?

一些可能有用的信息:我最近重新创建了数据库,我不知道这是否重要,但我最近也擦了硬盘,不得不重新安装我的本地git repo。如果有任何其他文件可以解决这个问题,请告诉我。谢谢!!!

堆栈跟踪:

4DV3R54RYs-MBP:Development D35TR0Y3R$ rake db:seed
rake aborted!
ArgumentError: The :dependent option must be one of [:destroy, :delete_all, :nullify, :restrict_with_error, :restrict_with_exception], but is :destroyend
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.5/lib/active_record/associations/builder/association.rb:140:in `check_dependent_options
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.5/lib/active_record/associations/builder/association.rb:90:in `define_callbacks
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.5/lib/active_record/associations/builder/collection_association.rb:27:in `define_callbacks
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.5/lib/active_record/associations/builder/association.rb:38:in build
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.5/lib/active_record/associations.rb:1259:in has_many
/Users/a666/Development/app/models/post.rb:2:in <class:Post>
/Users/a666/Development/app/models/post.rb:1:in <top (required)>
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in load
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in block in load_file
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:647:in new_constants_in
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:456:in load_file
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:354:in require_or_load
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:494:in load_missing_constant
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:184:in const_missing
/Users/a666/Development/db/seeds.rb:4:in block in <top (required)>
/Users/a666/Development/db/seeds.rb:3:in times
/Users/a666/Development/db/seeds.rb:3:in <top (required)>
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in load
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in block in load
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in load_dependency
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in load
/Users/a666/.rvm/gems/ruby-2.3.3/gems/railties-4.2.5/lib/rails/engine.rb:547:in load_seed
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:250:in load_seed
/Users/a666/.rvm/gems/ruby-2.3.3/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:183:in block (2 levels) in <top (required)>
/Users/a666/.rvm/gems/ruby-2.3.3/gems/rake-11.2.2/exe/rake:27:in <top (required)>
/Users/a666/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in eval
/Users/a666/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in <main>
Tasks: TOP => db:seed
(See full trace by running task with --trace)

seedfile:

require 'random_data'

50.times do
  Post.create!(
  title: RandomData.random_sentence,
  body: RandomData.random_paragraph
  )
end
posts = Post.all
100.times do
  Comment.create!(
  post: posts.sample,
  body: RandomData.random_paragraph
  )
end
100.times do
  Question.create!(
    title: RandomData.random_sentence,
    body: RandomData.random_paragraph,
    resolved: false
  )
end
puts "Seed finished"
puts "#{Post.count} posts created"
puts "#{Comment.count} comments created"
puts "#{Question.count} questions created"

0 个答案:

没有答案