Forum: Ruby on Rails Mysql error unknown column 'columns.user_id'

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ken L. (Guest)
on 2009-02-22 03:08
Had this error when trying to add comments to another user's photo.

ActiveRecord::StatementInvalid in User photosController#show
Mysql::Error: Unknown column 'comments.user_id' in 'on clause': SELECT
photos.`id` AS t0_r0, photos.`user_id` AS t0_r1, photos.`title` AS
t0_r2, photos.`body` AS t0_r3, photos.`created_at` AS t0....

I did create a user_id column in the comments as such:

class CreateComments < ActiveRecord::Migration
  def self.up
    create_table :comments do |t|
      t.column :photo_id, :integer
      t.column :user_id, :integer
      t.column :guest_name, :string
      t.column :guest_email, :string
      t.column :guest_url, :string
      t.column :body, :text
      t.column :created_at, :datetime
    end
    add_index :comments, :photo_id
  end

  def self.down
    drop_table :comments
  end
end

Can anyone tell me what went wrong and how to solve?
Evan (Guest)
on 2009-02-22 03:28
(Received via mailing list)
Can you paste the lines where that error is raised?
TonyBacellar (Guest)
on 2009-02-22 13:02
(Received via mailing list)
Hi  Ken!

If I understand very well  your problem! the database is not
recognizing this collumm. By  want i saw the collum was created  . but
we would have to analize the SQL command in complete. Just a shot!
Maybe in your sql command you are join two tables or more and if is
true you most to specify the origin of the field. Like this:

SELECT T01.FIELD01 , T02.FIELD01
FROM TABLE01 T01 , TABLE02 T02
WHERE T01.FIELD01 = T02.FIELD01

I hope i helped you !

Post the sql command in complete.

Tony Bacellar
removed_email_address@domain.invalid
delicious.com/tonybacellar
This topic is locked and can not be replied to.