我在表注釋上遇到了參考子彈的問題。我想從表格帖子中添加子彈帖子。所以當(dāng)我插入評論時,它可以將posttable中的commentable_slug放進去。這是我的評論表和帖子表。commentable_id = 32,這意味著post_id,您可以從post中看到該文件,即(quia-pariatur-expedita-vel-quia)評論表發(fā)布表和我的遷移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,因為它總是警告我無法添加或更新子行:外鍵約束失敗。當(dāng)我嘗試我的字段comableable為null時。如何解決我的問題?
自動插入新評論時如何在評論表引用中添加評論的表字段
慕工程0101907
2021-05-06 10:31:30