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

kimbbo's avatar

Run seeds with migrations together without truncating all tables.

Hi friends,

I have a problem/doubt. In my Laravel application I have several migrations and seeders. Now, I created one migration and his corrresponding seeder. When I launched the migration I would run only the seeder created. Like having in the up() method of the migration: insert + run seeder. I want 'associate' migrations with seeders to initial data loads automatically each migration without truncating all tables.

It's posibble?

Thank you very much for your time and answers.

0 likes
7 replies
rdelorier's avatar

I don't think there is any reason you cant just call the seeder from the migration.

kimbbo's avatar

@rdelorier It is just one example. I have a database in production. With my new migrations I want run his associated seeders automatically.

rdelorier's avatar

So should the seeder run every time the migration runs or do you just want to specify the seeder so you done mess up the entire database?

rdelorier's avatar
Level 9

If you need the to seed after a migration then that seed is part of the migration and should be fired by the migration itself.

note that you can specify a specific seeder class when you run php artisan db:seed --class=NewDataSeeder

public function up()
{
    //schema migrations here

    //now the data migration
    Artisan::call('db:seed', [
        '--class' => MigrationSpecificSeeder::class,
    ]);
}
7 likes
kimbbo's avatar

Excuse me, I not see your previous answer. That is what I want!.

Yes, in production, when I deploy, I want to do (example): php artisan migrate .Then, if my new migrations has associated seeders (for example, 3 new tables with initial data, I want than run migrations and seeders, and not only migrate and I run seeder one, run seeder two...run seeder 'n' after one by one.

kimbbo's avatar

@rdelorier thanks, is perfect this solution.

Now, other question. Would the following correct?. For example, I need insert new data in a table with 7 rows. Is correct create a migration only for call a seeder with new inserts?.

rdelorier's avatar

I would use use a seeder for sure just because if you don't then you won't be able to add the rows unless you run the migration each time you seed.

Please or to participate in this conversation.