Laravel 5.1 Migration and Seeding Cannot truncate a table referenced in a foreign key constraint

前端 未结 9 2148
借酒劲吻你
借酒劲吻你 2020-12-15 05:04

I\'m trying to run the migration (see below) and seed the database, but when I run

php artisan migrate --seed

I get this error:

<         


        
9条回答
  •  一向
    一向 (楼主)
    2020-12-15 05:25

    DB::statement('SET FOREIGN_KEY_CHECKS=0;');
    App\User::truncate();
    DB::statement('SET FOREIGN_KEY_CHECKS=1;');
    

    And it works!

提交回复
热议问题