✅ Migration-independent Database Seeding
Curious if EF has some sort of independent database seeding potential? I am kinda hoping to see a similar functionality to Laravel's Database Seeder where you can write the seed in a file which you can run at any time, regardless of whether or not your migrations are already ran. I find the
HasData
fucntiuonality inherently counterproductive as I don't want to re-run all migrations over and over just so I can work with my seed data.
Laravel Seeding: https://laravel.com/docs/11.x/seedingLaravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
35 Replies
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
Which is exactly my problem with it
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
I already have finalized the schema
Actually
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
And have the migrations for it, already ran, which means that the schema is now in the database and the tables are already generated
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
At which point, I started working with seeding hte database
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
I am pointing out what you can do with database seeding in Laravel, which you can actually run without running the migrations
Which can work with existing database schemas.
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
In laravel, migrations and seeders are independent of each other. YOu can write migrations without seeders, and you can write seeders without migrations.
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
it just throws an error
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
Just tells you that there's a problem when running the seed
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
It knows because it would try to run the SQL statement
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
just try it and see.
Anyhow, going back to the topic
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
Hmmm interesting.
Is it possible to run this from a
dotnet ef XXX
context?
sorta like
dotnet ef <New seed command> MySeeder
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
Just wrapping my head around this EFCore thing coming from a Laravel background
I find it weird
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
But I have to for ease of use.
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
I think it's nice to define DDLs on code
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
and make it easier for other folks working with me to understand what's happening
all the while being able to use dotnet tooling
you could make your own seed program as an alterantive start project. so instead of
dotnet run path/to/webapi
youd do dotnet run path/to/seeder/
Ooooh. So it's basically a new project inside my existing solution*?
yes
another alternative is to have your seeder run at startup of the web api, but check if it has already seeded
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
If you have no further questions, please use /close to mark the forum thread as answered