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

iwanzijderveld's avatar

Is it a bad idea to populate a table with default data from migration files?

I have a package that creates some tables, but for the package to work correctly it needs some default data. If I follow the documentation of Laravel I should go ahead and use the Seeder functionality. But the documentation states that it is used to seed your tables with test data, which in my case doesn't apply. I know I can just go ahead and populate the tables with Seeds anyway, but if someone runs the seeder twice the data also gets inserted twice.

A solution to this problem could be to just populate the tables with default data from a migration file. Which is guaranteed to run just once. So I was wondering if using that method is a bad idea and if so, why?

0 likes
2 replies
andreich1980's avatar

I do my seeders with firstOrCreate. So I can run the seeder as many times as I want

signar's avatar

@iwanzijderveld There is no right or wrong.. If you feel that the right thing to do is to populate a table from the migration file, then you do that! :) another solution would be to use firstOrCreate in a seeder like @andreich1980 said.

If you're testing I wouldn't worry too much if the seeder runs twice, but it's another story in production

Please or to participate in this conversation.