Rails 活动记录 SQLite3::SQLException: 没有这样的列: subs.subscriber_id: SELECT "subs".* FROM "subs" WHERE "subs"."subscriber_id"=?

Rails Active Records SQLite3::SQLException: no such column: subs.subscriber_id: SELECT "subs".* FROM "subs" WHERE "subs"."subscriber_id" =?

我使用了 Has_manySubscriberSub models

的关系
class Sub < ActiveRecord::Base

  belongs_to :Subscriber
end

class Subscriber < ActiveRecord::Base
  has_many :subs

end

正在将记录插入 Sub table bu sung

我收到如下错误

错误日志

Rails Console.
 a=Subscriber.find(1)
  Subscriber Load (0.0ms)  SELECT  "subscribers".* FROM "subscribers" WHERE "subscribers"."id" = ? LIMIT 1  [["id", 1]]
=> #<Subscriber id: 1, name: "arun", created_at: "2015-12-22 07:38:34", updated_at: "2015-12-22 07:38:34">
irb(main):002:0> a.subs
  Sub Load (0.0ms)  SELECT "subs".* FROM "subs" WHERE "subs"."subscriber_id" = ?  [[nil, 1]]
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: subs.subscriber_id: SELECT "subs".* FROM "subs" WHERE "subs"."subscriber_id" = ?

使用

class Sub < ActiveRecord::Base
    belongs_to :subscriber
end

class Subscriber < ActiveRecord::Base 
    has_many :subs
end

确保 您有 运行 迁移。 不要在 associations.

中使用 CAPITAL

您也可以分享您的架构吗??

PS: 请缩进您的代码。

使用这个belongs_to :subscriber

如果不行的话

将 subscriber_id 列添加到 subs

键入以下 rails 命令

rails g migration AddSubscriber_idToSub subscriber_id:integer

然后

rake db:migrate