Added optional: true to belongs_to.
belongs_to :post, optional: true
From Rails5, if you try to store in the DB without data in either of the tables linked by default, an error will occur. So you need to write'optional: true' to make it ok even if there is no data in either.
Recommended Posts