Emil Emil - 11 months ago 107
MySQL Question

Laravel: Reset auto increment before re-seeding a table

Is there a way to set auto increment back to 1 before seeding a table?

I empty the table before seeding it and if I didn't do

before seeding it then it continues the auto increment of the ID from the last position, e.g., 4.

Table seed:

public function run()
// Product table seeder
$product = new \App\Product([
'category_id' => 1,
'image_path' => '/images/products/1/000001.jpg',
'title' => 'test',

Creating the table:

Schema::create('products', function (Blueprint $table) {

Answer Source

Try this:

DB::statement('SET FOREIGN_KEY_CHECKS=0');


Instead of