ActiveRecord :: StatementInvalid PG :: UndefinedColumn: ERROR

I am using rails_admin for admin panel. Just change the association in the image model.

From this

class Image < ApplicationRecord
   belongs_to :user 
   belongs_to :product 
end

to that

class Image < ApplicationRecord
   has_one :user 
   has_one :product 
end

and user model

class User < ApplicationRecord
   has_many :images,dependent: :destroy
end

Getting this error when I try to edit a user from the admin panel. On the other hand, it works fine.

ActiveRecord::StatementInvalid at /user/72/edit

PG::UndefinedColumn: ERROR:  column users.image_id does not exist
LINE 1: SELECT  "users".* FROM "users" WHERE "users"."image_id" = $1...
                                         ^
: SELECT  "users".* FROM "users" WHERE "users"."image_id" = $1 LIMIT $2
+4
source share
1 answer

Rails . has_one , : " , ", image_id user. ; . .

, , :

  • belongs_to :user has_one :user ? SQL Rails , has_many :images, belong_to ; , has_and_belongs_to_many. A B, B ( ) A. belongs_to, have_many . , : , .. (has_many :images). () (has_many :images), , , .
  • , attachinary paperclip. , , , , , .. , , .
+1

Source: https://habr.com/ru/post/1668516/


All Articles