dropPrimary(); }); // 2️⃣ Add new UUID column Schema::table('model_has_roles', function (Blueprint $table) { $table->uuid('model_id_new')->after('role_id'); }); // 3️⃣ Copy existing data DB::statement(' UPDATE model_has_roles SET model_id_new = model_id '); // 4️⃣ Drop old column Schema::table('model_has_roles', function (Blueprint $table) { $table->dropColumn('model_id'); }); // 5️⃣ Rename new column to model_id Schema::table('model_has_roles', function (Blueprint $table) { $table->renameColumn('model_id_new', 'model_id'); }); // 6️⃣ Recreate primary key Schema::table('model_has_roles', function (Blueprint $table) { $table->primary(['role_id', 'model_id', 'model_type']); }); } public function down(): void { Schema::table('model_has_roles', function (Blueprint $table) { $table->dropPrimary(); }); Schema::table('model_has_roles', function (Blueprint $table) { $table->unsignedBigInteger('model_id_old')->after('role_id'); }); DB::statement(' UPDATE model_has_roles SET model_id_old = model_id '); Schema::table('model_has_roles', function (Blueprint $table) { $table->dropColumn('model_id'); }); Schema::table('model_has_roles', function (Blueprint $table) { $table->renameColumn('model_id_old', 'model_id'); }); Schema::table('model_has_roles', function (Blueprint $table) { $table->primary(['role_id', 'model_id', 'model_type']); }); } };