Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework update seed data - data motion migration

My seed data uses the HasData method for insert:

modelBuilder.Entity<SystemResource>().HasData(new[]
{
    new SystemResource()
    {
        Id = 1,
        Code = "roi-dev-003",
        IsEnabled = true,
    }
});

I would like to change the value of the Code property of generated seed data to a new value. Can it be done using seed data or is an sql update of DB needed?

The signature of the HasData method says it is used to generate data motion migration. How does a data motion migration work?

Update: Changing the value of Code property and then running update-database has no effect:

PM> update-database
No migrations were applied. The database is already up to date.
like image 382
Martin Staufcik Avatar asked Jul 20 '26 23:07

Martin Staufcik


1 Answers

Unfortunately, it doesn't appear that this functionality is supported in EFCore currently.

This article is a pretty in-depth overview of the HasData system. This line from it is relevant:

But HasData isn’t a silver bullet. Keep in mind that this feature is best for seed data that will remain static once it’s been inserted into the database.

I too have been looking for a good solution to this problem

like image 73
zxcv Avatar answered Jul 24 '26 06:07

zxcv