Question

I have multiple Migrations in my project, each migration adds a number of columns. After each migration, I want to fill data into the columns, based on the other already existing columns. I work in a team, and we each have a local database with test data.

Currently there is one single seed method in the configuration class.

With one migration adding columns, adding data in the seed method is fine, but with multiple migrations where every one of them adds columns, it will not work unless i update the seed method to match the most recent migration.

Why didn't they include a virtual or abstract Seed-method for people to override when needed in the DbMigration class? That would seem like a much better way?

Thanks in advance

Was it helpful?

Solution

Because you can seed your data directly in Up method in your migration class. Just call:

Sql("INSERT INTO ... ");
Sql("UPDATE ... ");

Seed method in migration configuration is more suitable for initial database seeding when the database is created but it can also be used for upcoming seeds when you need to add or update whole entities - not just initialize columns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top