【发布时间】:2015-08-12 18:13:05
【问题描述】:
我正在使用rails_admin gem。当我从 localhost 打开管理面板时它工作正常,但是每当我尝试在 Rails 管理面板中显示用户时都会收到此错误。
ActiveRecord::StatementInvalid in RailsAdmin::Main#show
PG::UndefinedColumn: ERROR: column relationships.user_id does not exist
LINE 1: ...LECT "relationships".* FROM "relationships" WHERE "relations...
^
: SELECT "relationships".* FROM "relationships" WHERE "relationships"."user_id" = $1
我意识到这个错误可能来自我的用户模型
class User < ActiveRecord::Base
has_many :relationships
has_many :active_relationships, class_name: "Relationship",
foreign_key: "follower_id",
dependent: :destroy
has_many :passive_relationships, class_name: "Relationship",
foreign_key: "followed_id",
dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
has_many :followers, through: :passive_relationships, source: :follower
end
relationship.rb
class Relationship < ActiveRecord::Base
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
end
我完全不知道为什么错误说relationship.user_id 不存在。我怎样才能解决这个问题?提前致谢。
【问题讨论】: