Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlvin Shern
3,421 PointsCreating Customer Data on Rails Console
Hi, I have managed to follow along this video until the very end where Hampton creates customer data for Bob's Emporium. In the Rails Console, he entered: Customer.create(name: "Bob's Emporium", email: "bob@emporium.com"). When I tried to enter this I got the following error:
from bin/rails:4:in `<main>'irb(main):011:0> Customer.create(name: "Bob's Emporium", email: "bob@empor
ium.com")
ActiveRecord::UnknownAttributeError: unknown attribute 'name' for Customer.
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/attribute_assignment
.rb:59:in rescue in _assign_attribute'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/attribute_assignment
.rb:54:in
_assign_attribute'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/attribute_assignment
.rb:41:in block in assign_attributes'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/attribute_assignment
.rb:35:in
each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/attribute_assignment
.rb:35:in assign_attributes'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/core.rb:564:in
init
_attributes'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/core.rb:281:in init
ialize'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/inheritance.rb:61:in
new'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/inheritance.rb:61:in
new'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.3/lib/active_record/persistence.rb:33:in
create'
from (irb):11
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in star
t'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in
start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in
console'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in
run_command!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in <top (require
d)>'
from bin/rails:4:in
require'
from bin/rails:4:in `<main>'
1 Answer
Charles Lee
17,825 PointsIt seems when you made your own Customer model or when you were creating the migration for the Customer model, you may have left out the name
attribute. If we look at the error, we see:
ActiveRecord::UnknownAttributeError: unknown attribute 'name' for Customer
Check your model and/or migration for Customer and try again. Hope this helps!