我有一个附件表,它与其他表具有多态关系。我想在文件选择上上传一个文件并将其插入到attachments
表中,但是在创建父记录之前,该记录与任何父表都不相关,因此对于这两个字段attachable_id
,attachable_type
应该可以为空。以下是附件表迁移:
schema::table('attachments', function (Blueprint $table) {
$table->nullableMorphs('attachable');
});
但是当我创建附件记录时,它显示一个错误。
$attachment = new Attachment();
$attachment->name = 'name';
.........
.........
$attachment->save();
"message": "SQLSTATE[HY000]: General error: 1364 Field 'attachable_id' doesn't have a default value