Why “Laravel Seeder Not Working” Happens So Often
If Laravel Seeder Not Working is the issue you are facing this week, you picked a strong SEO topic and a useful one for readers too. Seeders look simple on the surface, but they depend on several moving parts working together: the class must be in the right place, the namespace must match, the database connection must be correct, the table must already exist, and the seeder must actually be called from DatabaseSeeder or through the --class option. Laravel’s official documentation confirms that seeders live in database/seeders, the default entry point is DatabaseSeeder, and you can run either all seeders or a specific seeder class with Artisan. (Laravel)
That is why this problem shows up in so many forms. Sometimes the command runs but inserts nothing. Sometimes it throws a “class not found” error. Sometimes it fails because the migration never ran. And sometimes the data goes into the wrong database because the environment configuration is off. Laravel also stores database connection settings in config/database.php, which are usually driven by environment variables, so a bad .env value can quietly send you in circles. (Laravel)
The good news is that this issue is usually fixable in minutes once you debug it in the right order.
How Laravel Seeding Works in Plain English
Laravel includes built-in support for database seeding through seed classes. Those classes live in the database/seeders directory, and each class has a run() method that inserts records either through the query builder or Eloquent model factories. By default, the db:seed command runs the Database\Seeders\DatabaseSeeder class, and that class can call other seeders in sequence. Laravel also disables mass-assignment protection during seeding, which makes inserts easier in this context. (Laravel)
Where seeder classes live
In current Laravel versions, seeders belong in database/seeders and use the Database\Seeders namespace. That structure matters. If the file is in the wrong folder or the namespace is wrong, Laravel may not find the class at all. This became especially important after older Laravel versions moved away from the old database/seeds pattern. (Laravel)
What DatabaseSeeder actually does
Think of DatabaseSeeder as the master switch. When you run:
php artisan db:seed
Laravel executes DatabaseSeeder, and inside it you typically call child seeders like this:
$this->call([
UserSeeder::class,
PostSeeder::class,
]);
If your specific seeder is not referenced there, it may never run unless you call it directly with --class. Laravel’s documentation explicitly supports both approaches. (Laravel)
The Most Common Laravel Seeder Errors
When people search Laravel Seeder Not Working, they usually mean one of a few repeat offenders.
Seeder class not found
This usually points to a namespace mismatch, wrong class name, wrong file name, or autoload issue. If the class is missing from database/seeders, named incorrectly, or not under the Database\Seeders namespace, Artisan may fail to locate it. The Laravel 8 upgrade notes also highlight the importance of namespaced seeders and the database/seeders directory. (Laravel)
Nothing inserts into the database
This is the sneaky one. The command appears to run, but the table stays empty. That usually means the seeder logic is not executing, the wrong database connection is being used, the code is conditional in a way that skips inserts, or the factory is misconfigured. Since Laravel database connections are driven by configuration and environment values, this is often a configuration issue rather than a seeding issue. (Laravel)
Target table does not exist
If the migration never ran, the seeder has nowhere to insert data. Laravel’s migration system defines the schema, while seeders populate it. In simple terms: migration first, seeding second. (Laravel)
Duplicate data problems
This happens when you rerun the seeder again and again without making it idempotent. The first run works, but the second one creates duplicate rows or crashes on unique constraints. This is not always a Laravel problem; often it is a data design problem.
Laravel Seeder Not Working: Step-by-Step Fixes
Fix 1: Confirm the seeder is being called
Start with the simplest check. If you are running all seeders, make sure your seeder class is included inside DatabaseSeeder:
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$this->call([
UserSeeder::class,
]);
}
}
Or run the seeder directly:
php artisan db:seed --class=UserSeeder
Laravel officially supports both methods. If the seeder is not called, nothing else matters. (Laravel)
Fix 2: Check namespace and file location
Make sure all of these line up:
-
file location:
database/seeders/UserSeeder.php -
namespace:
namespace Database\Seeders; -
class name:
class UserSeeder extends Seeder
If you copied old code from an older project, you may still have the old structure in mind. Current Laravel docs use database/seeders and Database\Seeders. (Laravel)
If needed, refresh Composer’s autoload files:
composer dump-autoload
That often clears out “class not found” headaches after moving files around.
Fix 3: Run migrations before seeding
If the table does not exist, the seeder cannot succeed. Run:
php artisan migrate
php artisan db:seed
Or, if you are in a disposable local database:
php artisan migrate:fresh --seed
Laravel’s migration docs describe migrations as the mechanism for defining tables, columns, and indexes, while seeding fills those tables afterward. (Laravel)
Fix 4: Verify the database connection
This one bites hard in local development. Your seeder may be working perfectly but writing to a different database than the one you are inspecting. Check:
-
DB_CONNECTION -
DB_DATABASE -
DB_HOST -
DB_PORT -
DB_USERNAME
These values feed Laravel’s database configuration. If you changed .env, clear stale config before testing again:
php artisan config:clear
php artisan cache:clear
Laravel’s configuration and database docs both note that database settings are defined through configuration files and environment variables. (Laravel)
Fix 5: Use factories correctly
Laravel seeders can use manual inserts or model factories. If you are using a factory, confirm that:
-
the model exists
-
the factory exists
-
the relationships make sense
-
required fields are populated
A clean example:
use App\Models\User;
User::factory()->count(10)->create();
Laravel’s seeding docs explicitly support Eloquent model factories inside seeders. (Laravel)
Fix 6: Prevent duplicate records
If your seeder is intended to be rerun, do not rely on blind inserts. Use one of these patterns:
User::updateOrCreate(
['email' => '[email protected]'],
['name' => 'Admin User']
);
Or truncate in local-only workflows before reseeding. Be careful with truncation if foreign keys are involved.
A simple rule helps here:
| Situation | Better approach |
|---|---|
| Static reference data | updateOrCreate() |
| Disposable local test data | migrate:fresh --seed |
| Production-safe defaults | Specific seeder classes only |
Fix 7: Watch model events and side effects
Laravel provides the WithoutModelEvents trait for seeders when you want to mute model events during seeding. That matters if your models trigger observers, queued jobs, notifications, or other side effects that slow down or break the seed process. Laravel’s seeding docs document this option directly. (Laravel)
Example:
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
use WithoutModelEvents;
public function run(): void
{
// seed data
}
}
This is especially useful when the seeder “works” but creates unexpected behavior.
Fix 8: Clear stale config and autoload issues
Two tiny commands solve a shocking number of annoying bugs:
php artisan optimize:clear
composer dump-autoload
Why? Because Laravel caches configuration and Composer controls autoloading. If you renamed files, changed namespaces, or updated .env, stale state can make the app act like nothing changed.
Fix 9: Test the result properly
Do not stop at “the command ran.” Confirm the data actually exists.
Laravel’s database testing tools let you seed during tests and assert records exist in the database. The official testing docs show that you can run seeders in tests with seed() and verify database state with assertions. (Laravel)
Example test idea:
$this->seed(UserSeeder::class);
$this->assertDatabaseHas('users', [
'email' => '[email protected]',
]);
That turns a one-time fix into a repeatable guarantee.
A Clean Working Seeder Example
Here is a practical pattern you can adapt:
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
public function run(): void
{
User::updateOrCreate(
['email' => '[email protected]'],
[
'name' => 'Admin User',
'password' => bcrypt('password'),
]
);
User::factory()->count(10)->create();
}
}
And in DatabaseSeeder:
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$this->call([
UserSeeder::class,
]);
}
}
Then run:
php artisan migrate
php artisan db:seed
This pattern is easy to read, easy to debug, and much harder to break by accident.
Best Practices for Production and Local Development
This is where many developers save themselves future pain. Use seeders differently in local and production.
For local development, demo data is helpful. For production, fake content is risky. Laravel lets you run a specific seeder class with --class, which makes selective production seeding much safer than running every seeder blindly. (Laravel)
A safe workflow looks like this:
| Environment | Recommended approach |
|---|---|
| Local | Factories, demo data, migrate:fresh --seed |
| Staging | Limited realistic seed data |
| Production | Only essential seeders such as roles, permissions, settings |
This is also a smart place to mention the official Laravel seeding documentation for deeper framework examples and edge cases. (Laravel)
Another good habit is to keep seeders small and focused. One seeder for users. One for categories. One for settings. One for roles. When a big “everything seeder” breaks, debugging becomes messy fast.
FAQ: Laravel Seeder Not Working
Why is my Laravel seeder running but not inserting data?
Usually because the wrong database connection is active, the seeder is not actually being called, or the insert logic is conditional and silently skips execution. Laravel database connections are driven by configuration and environment variables, so checking .env is essential. (Laravel)
How do I run a specific seeder in Laravel?
Use:
php artisan db:seed --class=UserSeeder
Laravel officially supports the --class option for running a specific seeder. (Laravel)
Where should Laravel seeder files be stored?
Seeder classes should live in the database/seeders directory and typically use the Database\Seeders namespace. (Laravel)
Do I need to run migrations before seeding?
Yes. Migrations define the schema; seeders populate it. If the table does not exist yet, the seeder cannot insert records. (Laravel)
Can factories be used inside seeders?
Yes. Laravel’s seeding documentation explicitly allows using Eloquent model factories inside seeders. (Laravel)
How do I avoid duplicate records when reseeding?
Use idempotent patterns such as updateOrCreate(), or reset disposable local databases with migrate:fresh --seed instead of repeatedly inserting the same static rows.
Should I seed fake data in production?
Usually no. In production, run only essential seeders, such as roles or settings, and avoid demo content unless it is intentional and safe. Running specific classes with --class is safer than seeding everything. (Laravel)
Conclusion
If Laravel Seeder Not Working is blocking your progress, the fix is usually not complicated. Start with the basics: confirm the seeder is called, verify the namespace and file location, make sure migrations have run, double-check the active database connection, and clear stale cache or autoload state. From there, improve reliability with factories, idempotent inserts, and tests.