Ift*_*din 7 mysql laravel eloquent
下面的迁移脚本在旧版本的Laravel中运行平稳,但是我将其添加到了新的Laravel 5.8中并运行了该脚本。我越来越Error: foreign key was not formed correctly
评估迁移:
public function up() {
Schema::create('evaluation', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned()->index();
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
Run Code Online (Sandbox Code Playgroud)
用户迁移:
public function up() {
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
Bil*_*win 17
正如我们在上面的评论中讨论的那样,外键列必须与其引用的主键具有相同的数据类型。
你宣布你的user.id
主键$table->bigIncrements('id')
成为BIGINT UNSIGNED AUTO_INCREMENT
在MySQL语法。
您必须声明$table->unsignedBigInteger('user_id')
将BIGINT UNSIGNED
在MySQL中使用的外键,使其与user.id
列的外键兼容。
归档时间: |
|
查看次数: |
2664 次 |
最近记录: |