我正在使用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 _pharmacy
。images
(errno: 150 "外键约束格式不正确"( (SQL: 更改表images
添加约束images_visit_id_foreign
外键 (visit_id
( 引用visits
(id
((
我该如何解决这个问题?
更新visits
和images
的schema
,如下所示。 然后运行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');
});
}