Laravel“外键约束格式不正确”

时间:2021-04-15 16:36:15

标签: php laravel

我在 Laravel 迁移方面遇到了一些问题。 我按照书做了所有事情,迁移工作正常,但是当我尝试使用 uuids 安装 laravel 护照时,它给了我一个错误,即表国家“外键约束形成不正确”。 我尝试添加

Schema::disableForeignKeyConstraints();
Schema::dropIfExists('countries');

在 down 函数中,但没有成功。

这就是我的迁移的样子:

Schema::create('countries', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('currency_id')->nullable();
            $table->string('name');
            $table->string('iso_alpha_2')->unique();
            $table->string('iso_alpha_3')->unique();
            $table->string('native_name');
            $table->integer('phone_code');
            $table->string('capital')->nullable();
            $table->string('continent')->nullable();
            $table->json('languages')->nullable();
            $table->text('address_format')->nullable();
            $table->string('flag')->nullable();
            $table->text('time_zone')->nullable();
            $table->string('locales')->nullable();

            $table->timestamps();
            $table->softDeletes();
            $table->foreign('currency_id')->references('id')->on('currencies');

        });

我做错了什么?

完全错误:

<块引用>

SQLSTATE[HY000]:一般错误:1005 无法创建表 ecomet_git.countries (errno: 150 "外键约束是 格式不正确") (SQL: create table countries (id char(36) not null, currency_id char(36) null, name varchar(255) not null, iso_alpha_2 varchar(255) 不为空,iso_alpha_3 varchar(255) 不为空 null, native_name varchar(255) not null, phone_code int not null, capital varchar(255) null, continent varchar(255) null, languages json null, address_format text null, flag varchar(255) null, time_zone 文本 null, locales varchar(255) null, created_at 时间戳为空,updated_at 时间戳为空,deleted_at 时间戳 null) 默认字符集 utf8mb4 collat​​e 'utf8mb4_unicode_ci')

在 C:\xampp\htdocs\eComet\vendor\laravel\framework\src\Illuminate\Database\Connection.php:678 674â–• // 如果尝试运行查询时发生异常,我们将格式化错误 675â–• // 包含与 SQL 的绑定的消息,这将使此异常成为 676â–• // 对开发人员更有帮助,而不仅仅是数据库的错误。 677â–• catch (Exception $e) { â–678â–• throw new QueryException( 第 679 章 680°–•); 第 681 章 682°

1
C:\xampp\htdocs\eComet\vendor\laravel\framework\src\Illuminate\Database\Connection.php:471 PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table ecomet_git.countries (errno: 150 "Foreign key 约束形成不正确")")

2
C:\xampp\htdocs\eComet\vendor\laravel\framework\src\Illuminate\Database\Connection.php:471 PDOStatement::execute()

0 个答案:

没有答案
相关问题