ef core using system calendar format for generating migration names.
example of standard migration name for the Gregorian calendar on windows:
20190206144020_MIGRATION-NAME
But if the date format of Windows is something other than the Gregorian, like Persian calendar the ef core migration name generates something like :
13971114210223_MIGRATION-NAME
in a team project, we cannot use both formats because it's changing the order of migrations.
is there any way to fix that issue without changing windows calendar format or manually rename the migration?
version: EF core 2.2
This is simply a bug in the MigrationsIdGenerator class for the latest at this time EF Core 2.2.4 - in the last line of GenerateId
method:
return timestamp.ToString(Format) + "_" + name;
they simply forgot to pass CultureInfo.InvariantCulture
to DateTime.Format
method.
It's already fixed in the current code (I believe for EF Core 3.0), so you either wait for it, or copy/paste the current code to your project (rename the class to let say FixedMigrationsIdGenerator
) and then inside your DbContext
derived class, override OnConfiguring
and add the following (with the necessary using
s):
optionsBuilder.ReplaceService<IMigrationsIdGenerator, FixedMigrationsIdGenerator>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With