Skip to content

Commit

Permalink
feat: Disable Foreign before running seeders
Browse files Browse the repository at this point in the history
Modified DatabaseSeeder.php to temporarily disable
foreign key checksbefore truncating tables, ensuring
smooth database seeding without constraint violations.

Fixes hngprojects#626
  • Loading branch information
idehen-divine committed Mar 2, 2025
1 parent 307820c commit e7e656f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;

use App\Models\Job;
use App\Models\Organisation;
use App\Models\Profile;
use App\Models\User;
use App\Models\Profile;
use App\Models\Organisation;
use Illuminate\Database\Seeder;
use App\Models\UserSubscription;
use Illuminate\Support\Facades\DB;
use Database\Factories\BlogFactory;
use Illuminate\Database\Seeder;


class DatabaseSeeder extends Seeder
Expand All @@ -20,6 +21,8 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
// Disable foreign key checks
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
//create an admin user
$this->call([
AdminSeeder::class
Expand Down Expand Up @@ -89,5 +92,7 @@ public function run(): void
QuestMessageSeeder::class,
]);

// Enable foreign key checks
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
}
}

0 comments on commit e7e656f

Please sign in to comment.