Seeding database during migration fails when using newly added Enum
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Start with the migration flow in EFCore.Relational/Migrations/Internal/Migrator.cs, especially the seeding and ReloadTypes order linked in the issue. Reproduce with the EF Core 9 migration bundle, newly added PostgreSQL enum, and seeder described in the issue; compare the failure before and after calling ReloadTypes. Done means seeding during migration can use the new enum without either reported exception.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have a migration in EF Core 9 (package: Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4) adding new enum type:
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:Enum:event_stack_event_status", "closed,new,taken,unknown")
The enum is registered like so:
services.AddDbContext<DatabaseContext>(options =>
{
options.UseNpgsql(
CreateConnString(variables.DatabaseName),
npsqlOptions =>
{
npsqlOptions.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
npsqlOptions.MapEnum<EventStackEventStatus>();
});
options.UseDataSeeding();
options.ConfigureWarnings(c => c.Log((RelationalEventId.CommandExecuted, LogLevel.Debug)));
}, ServiceLifetime.Transient);
The UseDataSeeding is my extension simply adding seeder implementation:
public static void UseDataSeeding(this DbContextOptionsBuilder options)
{
options.UseSeeding(
(ctx, storeManagementPerformed) => SeedAsync(ctx, storeManagementPerformed).Wait());
options.UseAsyncSeeding(SeedAsync);
}
Migration is applied via migration bundle. During the seed process, where the enum is used, I'm getting error:
System.NotSupportedException: The data type name 'event_stack_event_status' isn't present in your database. You may need to install an extension or upgrade to a newer version.
As far as I know this is an issue with type cache which doesn't contain new enum mapping. I tried to call ReloadTypes in data seeder on current database connection from database context but it changed error to:
System.InvalidCastException: Writing values of 'EventStackEventStatus' is not supported for parameters having DataTypeName 'public.event_stack_event_status'
I'm aware of this issue: #292 and PR that solving it #2951, but it's not applying here because seeder is called during Migrate method before ReloadTypes is called: https://github.com/dotnet/efcore/blob/main/src/EFCore.Relational/Migrations/Internal/Migrator.cs#L192
The only workaround I see right now is to move data seeding to application start. Is there a way to solve it so I can still use data seeding during migration?
- Lingua principale
- C#
- Stelle
- 1.8k
- Fork
- 268
- Merge medio
- 2h 35m
- PR unite (30g)
- 136
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npgsql/efcore.pg
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
NTS: the M ordinate is dropped from geometry SQL literals and from geometries stored in JSONForse già presa @Ahmed7991 l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
npgsql/efcore.pg#4093 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
`TimeSpan`/`Duration` component members: negative values are floored, and intervals computed in SQL are read field by fieldForse già presa @jeremy-morren l’ha presa 11 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Numeric storage parameters are formatted with the current culture, so migrations emit 0,01 instead of 0.01Forse già presa @Sorbitol l’ha presa 12 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
-
`Contains` on a JSON primitive collection compares JSON text, so `DateTime` and `TimeOnly` items never matchForse già presa @Mr444-dev l’ha presa 7 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
npgsql/efcore.pg#4099 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di npgsql/efcore.pg
Issue simili
-
Issue-Bug Needs-Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
JiaFeiMiao-K-Cat/DiscImageStudio#281 ·
I maintainer di solito rispondono entro 1 giorno
-
area/access-management Frontend onboarding candidate :handshake:
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
Altinn/altinn-auth#4941 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
aws/aws-sdk-net#4586 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
Kryptos-FR/MarkView.Avalonia#269 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno