Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 4 months ago.
0

If you're on MySQL (and you probably are) try to turn off foreign key checks using this statement before you truncate data in tables with foreign key constraints.

<?php
DB::statement("SET foreign_key_checks = 0");

A reasonable place to put this would be app/database/seeds/DatabaseSeeder.php at the beginning of run() method.

Last updated 4 months ago.
0

I use DB::table('lessons')->delete();

Last updated 4 months ago.
0

@Oliver Thanks for different solution, I haven't tried but in my case setting foreign key check more reasonable.

Last updated 4 months ago.
0

Sign in to participate in this thread!

LoadForge

Your banner here too?

metude metude Joined 13 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.