gpt4 book ai didi

laravel - 外键约束的格式不正确(Laravel 迁移)

转载 作者:行者123 更新时间:2023-12-02 16:36:09 24 4
gpt4 key购买 nike

<分区>

如错误日志中所写,可能错误是由于引用表和父表中的不同形式引起的,但我还是不明白,因为我是编程新手

这里是表 1

<?php

Schema::create('questions', function (Blueprint $table) {
$table->id();
$table->string('question');
$table->unsignedInteger('quiz_id');
$table->timestamps();
});

这里是表 2

<?php

Schema::create('answers', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('question_id');
$table->string('answer');
$table->boolean('is_correct');
$table->timestamps();
});

Schema::table('answers', function (Blueprint $table){
$table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
});

我应该在此代码中更改什么?谢谢

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com