title: Laravel 8.54 Migration and Seeding Cannot truncate a table referenced in a foreign key constraint
body: <p>I'm trying to seed my UserSeeder into my database but I keep running into this error:</p>
  <blockquote>
  <p>SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (<code>hospitalmanagement</code>.<code>role_user</code>, CONSTRAINT <code>role_user_user_id_foreign</code> FOREIGN KEY (<code>user_id</code>) REFERENCES <code>hospitalmanagement</code>.<code>users</code> (<code>id</code>)) (SQL: truncate table <code>users</code>)</p>
  </blockquote>
  <p>Here's my users table code</p>
  <pre><code>public function up()
  {
      Schema::create('users', function (Blueprint $table) {
          $table-&gt;id();
          $table-&gt;string('name');
          $table-&gt;text('photo')-&gt;default('images/default-user-photo.jpg');
          $table-&gt;string('email')-&gt;unique();
          $table-&gt;integer('phone')-&gt;unique();
          $table-&gt;integer('status')-&gt;default(1);
          $table-&gt;timestamp('email_verified_at')-&gt;nullable();
          $table-&gt;string('password');
          $table-&gt;string('slug')-&gt;nullable();
          $table-&gt;rememberToken();
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  <p>My roles table</p>
  <pre><code>public function up()
  {
      Schema::create('roles', function (Blueprint $table) {
          $table-&gt;id();
          $table-&gt;string('name')-&gt;unique();
          $table-&gt;string('slug')-&gt;unique();
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  <p>User role table</p>
  <pre><code>public function up()
  {
      Schema::create('role_user', function (Blueprint $table) {
          $table-&gt;primary(['role_id', 'user_id']);
          $table-&gt;foreignId('role_id')-&gt;constrained()-&gt;onDelete('cascade');
          $table-&gt;foreignId('user_id')-&gt;constrained()-&gt;onDelete('cascade');
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  <p>In my seeders file I have this in my RoleSeeder</p>
  <pre><code>public function run()
  {
      // Role::truncate();
  
      $role = new Role();
      $role-&gt;name = 'Super Admin';
      $role-&gt;slug = 'super-admin';
  
      $role = new Role();
      $role-&gt;name = 'Admin';
      $role-&gt;slug = 'admin';
  
      $role = new Role();
      $role-&gt;name = 'Doctor';
      $role-&gt;slug = 'doctor';
  }
  </code></pre>
  <p>UserSeeder file</p>
  <pre><code>public function run()
  {
      User::truncate();
  
      $user = new User();
      $user-&gt;name = 'Super Admin';
      $user-&gt;email = 'admin@gmail.com';
      $user-&gt;phone = '0278596525';
      $user-&gt;role_id = 1;
      $user-&gt;password = '$2y$10$wSoyqSUQZGC8MeEcbqu2gugCgGTOuJz5AiKCphM6W2rK8swfb2/ky';
      $user-&gt;created_at = Carbon::now()-&gt;toDateTimeString();
      $user-&gt;save();
  
      $user = new User();
      $user-&gt;name = 'Admin';
      $user-&gt;email = 'add@gmail.com';
      $user-&gt;phone = '0247859662';
      $user-&gt;role_id = 2;
      $user-&gt;password = '$2y$10$wSoyqSUQZGC8MeEcbqu2gugCgGTOuJz5AiKCphM6W2rK8swfb2/ky';
      $user-&gt;created_at = Carbon::now()-&gt;toDateTimeString();
      $user-&gt;save();
  
      $user = new User();
      $user-&gt;name = 'Doctor';
      $user-&gt;email = 'doc@gmail.com';
      $user-&gt;phone = '0247899663';
      $user-&gt;role_id = 3;
      $user-&gt;password = '$2a$12$CMMLYGNwNreJlghJY3O3b.U4k2QJ7fhXdAA4XtfRXTPEEtBZenYNq';
      $user-&gt;created_at = Carbon::now()-&gt;toDateTimeString();
      $user-&gt;save();
  }
  </code></pre>