2015-06-16 47 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

回答

相關問題