char('uuid_tmp', 36)->nullable()->after('id'); }); // Step 2b: Populate UUIDs for all existing users $users = User::all(); foreach ($users as $user) { $user->uuid_tmp = (string) Str::uuid(); $user->save(); } // Step 2c: Make UUID column NOT NULL Schema::table('users', function (Blueprint $table) { $table->char('uuid_tmp', 36)->nullable(false)->change(); }); // Step 2d: Drop primary key and old id column, then rename uuid_tmp to id Schema::table('users', function (Blueprint $table) { $table->dropPrimary('PRIMARY'); }); Schema::table('users', function (Blueprint $table) { $table->dropColumn('id'); }); Schema::table('users', function (Blueprint $table) { $table->char('id', 36)->primary()->change(); }); Schema::table('users', function (Blueprint $table) { $table->renameColumn('uuid_tmp', 'id'); }); } public function down(): void { // ⚠️ Rollback is complicated for PK changes — you might need manual fixes Schema::table('users', function (Blueprint $table) { $table->dropPrimary('PRIMARY'); $table->dropColumn('id'); $table->bigIncrements('id'); }); } };