【问题标题】:Laravel 5.8 error SQLSTATE[HY000]: General error: 1005 uuidLaravel 5.8 错误 SQLSTATE[HY000]: 一般错误: 1005 uuid
【发布时间】:2020-05-26 20:46:52
【问题描述】:

我正在使用 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 Can't create table doctors _pharmacy.images (errno: 150 "外键约束格式不正确") (SQL: alter table images add constraint images_visit_id_foreign外键 (visit_id) 引用 visits (id))

我该如何解决这个问题?

【问题讨论】:

    标签: laravel-5 eloquent laravel-5.8


    【解决方案1】:

    如下更新schemavisitsimages。 然后运行php artisan migrate cmd。

    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');
    
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-20
      • 2014-01-26
      • 2021-09-10
      • 1970-01-01
      • 2020-03-19
      • 2012-10-24
      • 1970-01-01
      • 2017-01-31
      相关资源
      最近更新 更多