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?
on 2009-02-22 03:08
on 2009-02-22 03:28
Can you paste the lines where that error is raised?
on 2009-02-22 13:02
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 firstname.lastname@example.org delicious.com/tonybacellar