rails5 belongs_to 默认不能为空,报错must exist

1: 在config/application.rb设置 config.active_record.belongs_to_required_by_default = false

2: belongs_to 的时候添加optional: true

猜你喜欢

转载自zhangcaiyanbeyond.iteye.com/blog/2371728