2015-06-16 35 views
0

成功运行rake db:migrate后,试图运行rake db:seed --trace,但得到特殊错误NoMethodError: undefined method 'name' for nil:NilClassRails 4 - rake db:seed NoMethodError:未定义方法`name'为零:NilClass

不完全确定是什么问题。任何建议将不胜感激。谢谢!!

/usr/local/bundle/gems/activerecord-4.1.1/lib/active_record/associations/has_many_association.rb:74: warning: circular argument reference - reflection 
/usr/local/bundle/gems/activerecord4.1.1/lib/active_record/associations/has_many_association.rb:78: warning: circular argument reference - reflection 
/usr/local/bundle/gems/activerecord4.1.1/lib/active_record/associations/has_many_association.rb:82: warning: circular argument reference - reflection 
/usr/local/bundle/gems/activerecord4.1.1/lib/active_record/associations/has_many_association.rb:101: warning: circular argument reference - reflection 
rake aborted! 

NoMethodError: undefined method `name' for nil:NilClass 
/usr/local/bundle/gems/activerecord-4.1.1/lib/active_record/associations/has_many_association.rb:79:in `cached_counter_attribute_name' 
/usr/local/bundle/gems/activerecord-4.1.1/lib/active_record/associations/has_many_association.rb:75:in `has_cached_counter?' 
/usr/local/bundle/gems/activerecord-4.1.1/lib/active_record/associations/has_many_association.rb:83:in `update_counter' 
/usr/local/bundle/gems/activerecord-4.1.1/lib/active_record/associations/has_many_through_association.rb:65:in `insert_record' 
/usr/local/bundle/gems/activerecord-4.1.1/lib/active_record/associations/collection_association.rb:522:in `block (2 levels) in concat_records' 

#db/seeds.rb 

APP_KEYWORDS = YAML.load_file("#{Rails.root}/db/app_keywords.yml") 
User.create(email: '[email protected]', password: 'passwrd', password_confirmation: 'passwrd') 
User.create(email: '[email protected]', password: 'psswrd', password_confirmation: 'psswrd') 
User.create(email: '[email protected]', password: 'password', password_confirmation: 'password') 
User.create(email: '[email protected]', password: 'password', password_confirmation: 'password') 

APP_KEYWORDS["app"].each do |key,value| 
    app = App.find_or_create_by(name:key.downcase) 
    value.each do |val| 
    app.app_keywords.find_or_create_by(keyword:val.downcase) 
    end 
end 

["admin","moderator","venue_editor","user"].each do |role| 
    Role.find_or_create_by(name:role) 
end 

user = User.first 
user.add_role :admin 
+0

能否请您发表您的'DB/seeds.rb'文件尝试更新? – spickermann

+0

那么我会查看我的新迁移/模型是否与我播种的数据相匹配。 –

+3

你可能不需要发布整个seeds.rb。找到播种失败的地方。它可能试图创建一个依赖于尚未创建的另一个对象的对象。只需更改种子对象的顺序即可解决问题。 – MarsAtomic

回答

相关问题