Laravel seeder throws error when faking more than 15 records

  eloquent, laravel, laravel-8, php, sqlite

I’m seeding the test database with fake users, posts and categories but for some reason when I seed the database with more than 15 records Laravel throws this error:


  SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: (SQL: insert into "categories" ("name", "slug", "updated_at", "created_at") values (id, quibusdam-nihil-dignissimos-vitae-sint-minus-est-nostrum, 2021-06-22 17:52:02, 2021-06-22 17:52:02))

If I seed 15 or less records at once works fine.

This is the database seeder:


The Post factory:

public function definition()
        return [
            'user_id' => User::factory(),
            'category_id' => Category::factory(),
            'title' => $this->faker->sentence,
            'slug' => $this->faker->slug,
            'excerpt' => $this->faker->sentence,
            'body' => $this->faker->paragraph

And the category factory:

public function definition()
        return [
            'name' => $this->faker->word,
            'slug' => $this->faker->slug

I’m using Laravel 8 and the database is sqlite.

Source: Laravel

Leave a Reply