Laravel 5.8 错误 SQLSTATE[HY000]:一般错误:1005 uuid



我正在使用Laravel 5.8并打包"goldspecdigital/laravel-eloquent-uuid",因为我需要使用UUID4,这是我的迁移文件:

public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->bigIncrements('id');
// $table->timestamps();
$table->string('path');
$table->uuid('visit_id');
$table->foreign('visit_id')->references('id')->on('visits');
});
}

我收到以下错误:

SQLSTATE[HY000]:常规错误:1005 无法创建表doctors _pharmacyimages(errno: 150 "外键约束格式不正确"( (SQL: 更改表images 添加约束images_visit_id_foreign外键 (visit_id( 引用visits(id((

我该如何解决这个问题?

更新visitsimagesschema,如下所示。 然后运行php artisan migrate厘米。

visits表架构

public function up()
{
Schema::create('visits', function (Blueprint $table) {
$table->uuid('id')->primary();
// your column will be here
......
......
$table->timestamps();
});
}

images表架构

public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('path');
$table->uuid('visit_id');
$table->foreign('visit_id')->references('id')->on('visits');
});
}

最新更新