Laravel 5.1 Migration and Seeding Cannot truncate a table referenced in a foreign key constraint
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
App\User::truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
And it works!
As the error says, you can not truncate tables referenced by foreign keys. Delete should work though...
DB::table('some_table')->delete();
To clear
a table
using Eloquent
:
Model::query()->delete();
Example using default user model
User::query()->delete();