Rails .. Ever seen this error?

rails

#1

User Load (3.6ms) SELECT “users”.* FROM “users”
=> #<ActiveRecord::Relation [#<User id: 1, username: “Jon”, email: "jon@example.com", created_at: “2016-01-02 04:18:33”, updated_at: “2016-01-02 04:18:33”>, #<User id: 2, username: “Jack”, email: "jack@example.com", created_at: “2016-01-02 04:18:53”, updated_at: “2016-01-02 04:18:53”>]>
2.2.1 :002 > Comment
=> Comment(id: integer, descrption: text, user_id: integer, created_at: datetime, updated_at: datetime)
2.2.1 :003 > Comment.all
Comment Load (0.4ms) SELECT “comments”.* FROM “comments”
=> #<ActiveRecord::Relation []>
2.2.1 :004 > user = User.first
User Load (0.3ms) SELECT “users”.* FROM “users” ORDER BY “users”.“id” ASC LIMIT 1
=> #<User id: 1, username: “Jon”, email: "jon@example.com", created_at: “2016-01-02 04:18:33”, updated_at: “2016-01-02 04:18:33”>
2.2.1 :005 > user.comments
Comment Load (0.9ms) SELECT “comments”.* FROM “comments” WHERE “comments”.“user_id” = ? [[“user_id”, 1]]
=> #<ActiveRecord::Associations::CollectionProxy []>
2.2.1 :006 > comment = Comment.new(description: “This is a new comment”, user: user)
ActiveRecord::UnknownAttributeError: unknown attribute ‘description’ for Comment.
** from /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:59:in `rescue in _assign_attribute’**


#2

From the error, it seems that you are trying to access or set an un-existing attribute called description in the User model when trying to create a new user (User.new).

Make sure that your User model does have this attribute. You could check by doing the following:

  • Enter the rails console: rails console
  • Establish connection with Active Record: User.connection
  • Check the User table columns: User

In the output, check that the description column exists.

Also, it would be nice to see some code and some explanation as to where and how this error occurs.