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?