[RUBY] Rails must be exist error (@save is not executed)

Conclusion

Added optional: true to belongs_to.

belongs_to :post, optional: true

why?

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

Rails must be exist error (@save is not executed)
[Rails] Annotate is not executed when migrating
"tx" is not bound error
[Rails] fields_for is not displayed
Docker error: service must be a mapping, not a None Type.
[Rails 6] jQuery introduction ・ uncaught reference error $ is not defined Error solution
rails AWS deployment is not reflected
Data is not registered in Rails.
"" Application.js "is not present in the asset pipeline" error in Ruby on Rails
[Rails] About the error that the image is not displayed in the production environment
Rails g devise: install cannot be executed!
MySQL is not running stably ... Rails app is not running.
[Ruby On Rails] Error in test using RSpec MySQL client is not connected
[Rails] If CSS is not applied in collection_select, check if class can be specified.
The devise error message is not displayed properly.
[Error] ActiveRecord :: NoDatabaseError FATAL: database does not exist
Rails error messages cannot be translated into Japanese
rails new app is not created with app name
Ebean.update () is not executed in the inherited model.