From acbb1f040c97b004d5f3d03d99d26d2eec10576d Mon Sep 17 00:00:00 2001 From: mchev Date: Fri, 12 Jun 2026 14:43:27 +0200 Subject: [PATCH] fix(migrations): align FK column types with users/companies id on MySQL (#618) Laravel foreignId() creates BIGINT UNSIGNED columns, but users.id and companies.id use increments() (INT UNSIGNED). MySQL 8 rejects foreign keys when referencing and referenced column types differ (error 3780). Use unsignedInteger for impersonation_logs admin_id/user_id and for company_invitations company_id, user_id, and invited_by. Keep foreignId for role_id since roles.id is bigIncrements. This fixes upgrades from v2 on MySQL when running v3.0 migrations. Made-with: Cursor --- ...2026_04_03_070131_create_impersonation_logs_table.php | 4 ++-- ...026_04_03_204854_create_company_invitations_table.php | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/database/migrations/2026_04_03_070131_create_impersonation_logs_table.php b/database/migrations/2026_04_03_070131_create_impersonation_logs_table.php index 613858e6..b10dcfd8 100644 --- a/database/migrations/2026_04_03_070131_create_impersonation_logs_table.php +++ b/database/migrations/2026_04_03_070131_create_impersonation_logs_table.php @@ -10,8 +10,8 @@ return new class extends Migration { Schema::create('impersonation_logs', function (Blueprint $table) { $table->id(); - $table->unsignedBigInteger('admin_id'); - $table->unsignedBigInteger('user_id'); + $table->unsignedInteger('admin_id'); + $table->unsignedInteger('user_id'); $table->string('ip_address', 45)->nullable(); $table->unsignedBigInteger('token_id')->nullable(); $table->timestamp('stopped_at')->nullable(); diff --git a/database/migrations/2026_04_03_204854_create_company_invitations_table.php b/database/migrations/2026_04_03_204854_create_company_invitations_table.php index 8e0f6b70..f494eeef 100644 --- a/database/migrations/2026_04_03_204854_create_company_invitations_table.php +++ b/database/migrations/2026_04_03_204854_create_company_invitations_table.php @@ -10,13 +10,16 @@ return new class extends Migration { Schema::create('company_invitations', function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->constrained()->cascadeOnDelete(); - $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete(); + $table->unsignedInteger('company_id'); + $table->foreign('company_id')->references('id')->on('companies')->cascadeOnDelete(); + $table->unsignedInteger('user_id')->nullable(); + $table->foreign('user_id')->references('id')->on('users')->nullOnDelete(); $table->string('email'); $table->foreignId('role_id')->constrained('roles')->cascadeOnDelete(); $table->string('token')->unique(); $table->enum('status', ['pending', 'accepted', 'declined', 'expired'])->default('pending'); - $table->foreignId('invited_by')->constrained('users')->cascadeOnDelete(); + $table->unsignedInteger('invited_by'); + $table->foreign('invited_by')->references('id')->on('users')->cascadeOnDelete(); $table->timestamp('expires_at'); $table->timestamps();