почему ругается mysql на foreign key при попытке залить миграции ?laravel
первая в списке мииграция
class CreateLoadsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('loads', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('weight');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('loads');
}
}
//вторая миграция
class CreatePointsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('points', function (Blueprint $table) {
$table->id();
$table->integer('load_id');
$table->string('name');
$table->string('date');
$table->foreign('load_id')->references('id')->on('loads')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('points');
}
}
//ошибка
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 3780 Referencing column 'load_id' and referenced column 'id' in foreign key constraint 'points_load_id_foreign' are incompatible. (SQL: alter table `points` add constraint `points_load_id_foreign` foreign key (`load_id`) references `loads` (`id`) on delete cascade)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:692
688▕ // If an exception occurs when attempting to run a query, we'll format the error
689▕ // message to include the bindings with SQL, which will make this exception a
690▕ // lot more helpful to the developer instead of just the database's errors.
691▕ catch (Exception $e) {
➜ 692▕ throw new QueryException(
693▕ $query, $this->prepareBindings($bindings), $e
694▕ );
695▕ }
696▕ }
+9 vendor frames
10 database/migrations/2021_09_28_105239_create_points_table.php:23
Illuminate\Support\Facades\Facade::__callStatic()
+21 vendor frames
32 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Ответы (1 шт):
Автор решения: junior
→ Ссылка
не знаю как оно влияет, но заменил
$table->integer('load_id');
на
$table->unsignedBigInteger('load_id');
и все заработало)