我在表注释上遇到了参考子弹的问题。我想从表格帖子中添加子弹帖子。
所以当我插入评论时,它可以将posttable中的commentable_slug放进去。这是我的评论表和帖子表。commentable_id = 32,这意味着post_id,您可以从post中看到该文件,即(quia-pariatur-expedita-vel-quia)
评论表
发布表
和我的迁移
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('parent_id')->unsigned()->nullable();
$table->text('body');
$table->integer('commentable_id')->unsigned();
$table->foreign('commentable_id')->references('id')->on('posts')->onDelete('cascade');
$table->string('commentable_slug')->nullable();
$table->foreign('commentable_slug')->references('slug')->on('posts')->onDelete('cascade');
$table->string('commentable_type');
$table->timestamps();
});
我在commentable_slug中使用null,因为它总是警告我无法添加或更新子行:外键约束失败。
当我尝试我的字段comableable为null时。
如何解决我的问题?
Qyouu