嗨,我是 Ruby on Rails 的新手。我正在尝试创建一个小型博客站点。我有两张表帖子和评论。每个帖子都会有很多评论。我使用这些命令生成表。
rails g scaffold Post title:string body:text author:string
rails g scaffold Comment body:string author:string
现在我想将关系添加到模型类。我添加has_many :comments
到 Post 类和belongs_to :post
Comment 类。但是,当我尝试调用时,post.comments
我会收到运行时错误消息SQLException: no such column: comments.post_id
。我应该创建一个迁移并在 Comment 下添加 post_id 还是有办法在搭建脚手架时实现这一点?