关系has_many / belongs_to PG :: UndefinedColumn

时间:2016-09-22 21:42:10

标签: ruby-on-rails ruby rails-activerecord has-many belongs-to

执行此操作时出现此错误:

user.owned_tipsters

错误:

ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERREUR:  column tipsters.user_id does not exist

我的代码:

class User < ActiveRecord::Base

   has_many :owned_tipsters, class_name: 'Tipster', inverse_of: :owner
end

class Tipster < ActiveRecord::Base

  belongs_to :owner, class_name: 'User', inverse_of: :owned_tipsters
end

如果你能帮助我知道这个错误在哪里,我会感谢你

鲍里斯 THX

1 个答案:

答案 0 :(得分:2)

在您main

中添加foreign_key
user.rb