我正在开发一个Codeacademy日历应用,我正在使用我的rake db:seed遇到错误。任何人都可以帮助解释错误,以及如何解决它?
Eric-Parks-MacBook-Pro-2:calendar ericpark$ rake db:seed
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/values/time_zone.rb:285: warning: circular argument reference - now
rake aborted!
ActiveRecord::UnknownAttributeError: unknown attribute: date
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:50:in `rescue in _assign_attribute'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:45:in `_assign_attribute'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:26:in `each'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:26:in `assign_attributes'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/core.rb:452:in `init_attributes'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/core.rb:198:in `initialize'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/inheritance.rb:30:in `new'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/inheritance.rb:30:in `new'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/persistence.rb:33:in `create'
/Users/ericpark/rails_projects/calendar/db/seeds.rb:9:in `<top (required)>'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/railties-4.1.1/lib/rails/engine.rb:543:in `load_seed'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
NoMethodError: undefined method `date=' for #<Day id: nil, created_at: nil, updated_at: nil>
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activemodel-4.1.1/lib/active_model/attribute_methods.rb:435:in `method_missing'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_methods.rb:206:in `method_missing'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:45:in `public_send'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:45:in `_assign_attribute'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:26:in `each'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/attribute_assignment.rb:26:in `assign_attributes'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/core.rb:452:in `init_attributes'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/core.rb:198:in `initialize'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/inheritance.rb:30:in `new'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/inheritance.rb:30:in `new'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/persistence.rb:33:in `create'
/Users/ericpark/rails_projects/calendar/db/seeds.rb:9:in `<top (required)>'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/railties-4.1.1/lib/rails/engine.rb:543:in `load_seed'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Users/ericpark/.rvm/gems/ruby-2.2.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
我操纵了迁移文件。
种子档案:
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
d1 = Day.create(date: DateTime.parse('11th Jan 2015 00:00 AM'))
Event.create(name: "Ben Visiting", from: DateTime.parse('11th Jan 2015 00:00 AM'), to: DateTime.parse('12th Jan 2015 00:00 AM'), location: "", day_id: d1.id)
d2 = Day.create(date: DateTime.parse('12th Jan 2015 00:00 AM'))
d3 = Day.create(date: DateTime.parse('13th Jan 2015 00:00 AM'))
Event.create(name: "Taco Tuesday", from: DateTime.parse('13th Jan 2015 01:00 PM'), to: DateTime.parse('13th Jan 2015 03:00 PM'), location: "Brooklyn Taco Co. 120 Essex Street New York, NY 10002", day_id: d3.id)
d4 = Day.create(date: DateTime.parse('14th Jan 2015 00:00 AM'))
Event.create(name: "Pottery Painting", from: DateTime.parse('14th Jan 2015 06:00 PM'), to: DateTime.parse('14th Jan 2015 07:00 PM'), location: "The Art Cafe CH 326 Troy Avenue Brooklyn, NY 11213", day_id: d4.id)
d5 = Day.create(date: DateTime.parse('15th Jan 2015 00:00 AM'))
d6 = Day.create(date: DateTime.parse('16th Jan 2015 00:00 AM'))
Event.create(name: "Casual Friday", from: DateTime.parse('16th Jan 2015 00:00 AM'), to: DateTime.parse('17th Jan 2015 00:00 AM'), location: "", day_id: d6.id)
Event.create(name: "Running", from: DateTime.parse('16th Jan 2015 08:00 PM'), to: DateTime.parse('16th Jan 2015 08:30 PM'), location: "", day_id: d6.id)
Event.create(name: "Grocery Shopping", from: DateTime.parse('16th Jan 2015 09:00 PM'), to: DateTime.parse('16th Jan 2015 09:30 AM'), location: "", day_id: d6.id)
d6 = Day.create(date: DateTime.parse('17th Jan 2015 00:00 AM'))
这是附加的种子文件。
答案 0 :(得分:1)
从错误:
NoMethodError: undefined method `date=' for #<Day id: nil, created_at: nil, updated_at: nil>
您的表days
似乎没有任何日期列。可能有以下原因:
date
字段。