Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LucasDiniz's avatar

Database seeders don't seem to be called at all

I've a problem lately, I just started a 7.x Laravel project and, by the project requirements, , i need to use seeders to setup the system for usage, but for some unknown reason the "\Database\Seeders\DatabaseSeeder" class is not being called, i tried creating a single record on the database, using the methods: Model::create(), Model::insert(), DB::table()->insert(), and not a single one of those worked, the console outputs "Database seeding completed successfully." but no record was inserted on the database. I already checked the database connection with the "php artisan tinker" and tested all the methods that I tried on the seeder again, and all of them where inserted correctly on the database, I don't know if I am missing something on the configuration or installation that sets up the seeding procedure, but I couldn't figure out what i did wrong.

I even tried to throw an exception to see if the seeder is called, and i still got the the "Database seeding completed successfully." result from the "php artisan db:seed" command.

0 likes
14 replies
tykus's avatar

Do you call a different Seeder class inside the DatabaseSeeder parent class; or is everything written into \Database\Seeders\DatabaseSeeder???

Show that \Database\Seeders\DatabaseSeeder class

LucasDiniz's avatar

my code don't show up on replies .., nor the thread text, is there some tags that i need to use to show the code here?

tykus's avatar

@LucasDiniz wrap code within triple backticks (```) - the backticks on their own lines

    ```
    // your code
    ```
LucasDiniz's avatar

None of those attempts inserted anything, in the "php artisan tinker" they did work, but on migrations none inserted, but i got the "Database seeding completed successfully." message anyway.

class TipoUsuario extends Model
{
    protected $table = 'tipos_usuario';
    protected $fillable = [
        'nome'
    ];

    public $timestamps = false;

    public function usuarios()
    {
        return $this->hasMany(User::class, 'tipos_usuario_id');
    }

    public function habilidades()
    {
        return $this->hasMany(HabilidadeTipoUsuario::class, 'tipos_usuario_id');
    }
}

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        TipoUsuario::create([
            'nome' => 'Admin'
        ]);
        TipoUsuario::insert([
            'nome' => 'Admin'
        ]);
        DB::table('tipos_usuario')->insert([
            'nome' => 'Admin'
        ]);
    }
}

tykus's avatar

@LucasDiniz the Model class looks fine. So too does the DatabaseSeeder class; how are you calling the seeder?

If you temporarily add a dd('here') into the run method; does the command exit with the expected output?

LucasDiniz's avatar

@tykus I am calling it by the console command "php artisan db:seed", or at least I think that it's pre-configured to be called when the command is used on the console,

LucasDiniz's avatar

@tykus no, it didn't, even this don't affect the outcome:

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        throw new \Exception('error');
    }
}
tykus's avatar
tykus
Best Answer
Level 104

@LucasDiniz very odd. Is that DatabaseSeeder class in its right place; i.e. in the default composer.json file, the Database\Seeders namespace is mapped to "database/seeders/" directory?

1 like
LucasDiniz's avatar

@tykus is in the default "database/seeders/" directory, I didn't mess with this file, what I did do was creating a few new seeders, none of which worked and i traced it back their error to the fact that the default "Database\Seeders\DatabaseSeeder" file is not being called, as discussed above

LucasDiniz's avatar

Well, i found something pretty odd, there is two DatabaseSeeder files, one registered on the "composer.json" and other not, the strange part is both of them are identical, the one i was testing is the file in the folder which other seeder files get inserted by the "php artisan make:seeder" command, which is the "Seeder" directory, but there is a "Seed" directory with the same file, and it works!? Oh I found what I've done, I made the migrations in other Laravel version, copied to this one and they have a similar but different name, the strange part is, the other Laravel that I've tried didn't work because my programming environment doesn't support it, even the "vendor" folder wasn't generated, what a odd occurrence, ultimately my fault as aways, but still I don't get where the different directories came

LucasDiniz's avatar

@tykus Thank you very much for the help, your last answer really made me find out what was happening, and I even learned something new! Shamefully I didn't read the documentation in full, so I didn't knew that some configurations are set up in the "composer.json" file, I was searching all configuration files for naught

Please or to participate in this conversation.