3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-08-18 11:15:42 +00:00

Truncate the company_user pivot

This commit is contained in:
snipe
2026-07-16 15:26:28 +01:00
parent 61a8e82b70
commit d722728ba6

View File

@ -8,6 +8,7 @@ use App\Models\User;
use Database\Seeders\Concerns\ReportsMemory;
use Illuminate\Database\Eloquent\Factories\Sequence;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
@ -24,6 +25,13 @@ class UserSeeder extends Seeder
{
User::truncate();
// Truncate the company_user pivot too. Truncating users alone leaves
// orphaned pivot rows referencing the old user_ids; on the next reseed
// AUTO_INCREMENT hands out those same ids again, and any attempt to
// reattach a re-created user to the same company hits the
// (company_id, user_id) unique constraint.
DB::table('company_user')->truncate();
if (! Company::count()) {
$this->call(CompanySeeder::class);
}