Ограничения внешнего ключа несовместимы? - PullRequest
0 голосов
/ 18 октября 2019

Попытка заставить мои миграции работать после переделки некоторой логики таблицы, и я сталкиваюсь с проблемой при миграции. Что-то связанное с конфликтом ограничений.

При запуске php artisan migrate:fresh это показывает:

In Connection.php line 665:

  SQLSTATE[HY000]: General error: 3780 Referencing column 'cache_id' and referenced column 'id' in
   foreign key constraint 'cache_connections_cache_id_foreign' are incompatible. (SQL: alter table
   `cache_connections` add constraint `cache_connections_cache_id_foreign` foreign key (`cache_id`
  ) references `cache` (`id`))


In Connection.php line 459:

  SQLSTATE[HY000]: General error: 3780 Referencing column 'cache_id' and referenced column 'id' in
   foreign key constraint 'cache_connections_cache_id_foreign' are incompatible.

Миграции:

Schema::create('cache', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('item')->unique();
    $table->string('name');
    $table->string('picture');
    $table->string('description');
    $table->unsignedInteger('connection_count');
    $table->boolean('is_private');
    $table->json('additional_data')->nullable();
    $table->string('type_id');
    $table->timestamps();
});

Schema::create('cache_connections', function (Blueprint $table) {
    $table->bigInteger('cache_id');
    $table->string('connection');
    $table->timestamps();

    $table->foreign('cache_id')
        ->references('id')
        ->on('cache')
    ;
});

1 Ответ

3 голосов
/ 18 октября 2019

Это может быть связано с тем, что bigIncrements() использует unsignedBigInteger(), а не bigInteger(). Попробуйте обновить cache_connections миграцию, чтобы использовать метод без знака.

vendor / laravel / framework / src / Illuminate / Database / Schema / Blueprint.php

    /**
     * Create a new auto-incrementing big integer (8-byte) column on the table.
     *
     * @param  string  $column
     * @return \Illuminate\Database\Schema\ColumnDefinition
     */
    public function bigIncrements($column)
    {
        return $this->unsignedBigInteger($column, true);
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...