Migration for updated seed data does not set all enum values converted to string correctly #27575
Labels
area-migrations-seeding
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Overview
Apologies if this is known or expected behaviour, I could not find anything in the documentation or past issues along the lines, but I might of course have missed something. This is regarding some (to us, unexpected) behaviour we encountered when working with migrations and enum property values converted to their string representation in the database. We originally encountered the behaviour using
Pomelo.EntityFrameworkCore.MySql
provider, but I was also able to reproduce it usingMicrosoft.EntityFrameworkCore.SqLite
in version6.0.2
. Problem description has a short overview of what we observed and expected, and Steps to reproduce contains a link to a small repository demonstrating the reproduction.Problem description
Observed behaviour
Movie
) viaOnModelCreating
on aDbContext
and create a migration.Rating
, with valuesBad = 0
andGood = 1
) valued property (e.g.Rating
) toMovie
and configure that property to havestring
conversionRating
values with enum values that correspond to 0 (Bad
) and values that correspond to 1 (Good
)Rating
values whereGood
was set, leavingRating
values whereBad
was set at the converted default''
.Here is an example of seed data inserted by taking the above steps, generating a migrations script and applying it to a sqlite database:
Note the second value inserted:
(2,'A Documentary','')
- Instead, we would expect(2,'A Documentary','Bad')
Expected behaviour
Both
Bad
andGood
values are set in the subsequent migration. This is consistent with e.g. introducing a new seedMovie
with ratingBad
(which will be inserted correctly), or configuring the enum to start at value1
, which will cause all converted values to be inserted correctly.Steps to reproduce
I have uploaded a small repository reproducing the issue here: https://github.com/ehonda/MigrateConvertedEnumZeroes
It contains two commits. The first commit shows the state right after creating the migration seeding initial
Movie
data. The second commit shows the state right after creating the migration adding theRating
values.The script generated via
dotnet ef migrations script
is also included. Here we can see that the part corresponding to the second migration only updates the movie that got ratingGood
:Provider and version information
EF Core version:
6.0.2
Database provider:
Microsoft.EntityFrameworkCore.SqLite 6.0.2
Target framework:
.NET 6.0
Operating system:
Windows 10
The text was updated successfully, but these errors were encountered: