Error applying migrations dynamically with Npgsql and EF Core 9: Collation configuration not found in read-optimized model

Offen
#3,589 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
csharp, postgresql
Bereich
databases

Rechercherichtung

Start by reproducing the failure with EF Core 9.0.7 and Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4, using the multitenant context factory and calling Database.MigrateAsync(). Follow the reported stack trace from MigrationsModelDiffer.Diff through Migrator.HasPendingModelChanges; done means migrations apply without the collation exception, or the failure is narrowed to a minimal reproducible case.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Hello I encountered an error while applying migrations dynamically on mi multitenant application using EF Core 9.0.7 and Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4.

When I try to apply migrations to a specific schema I get the following exception:

System.InvalidOperationException: The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService<IDesignTimeModel>().Model'.
Stack trace:
   at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetCollation(IReadOnlyModel model)
   at Microsoft.EntityFrameworkCore.Metadata.IRelationalModel.get_Collation()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IRelationalModel source, IRelationalModel target, DiffContext diffContext)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.HasDifferences(IRelationalModel source, IRelationalModel target)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.HasPendingModelChanges()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.ValidateMigrations(Boolean useTransaction, String targetMigration)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<MigrateAsync>d__22.MoveNext()
   at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.<MigrateAsync>d__4.MoveNext()

The error happens when applying a migration:

public async Task<ClientMigrationResponse> ApplyOneClientMigrationsAsync(string clientCode)
{
    var clientContext = clientContextFactory.CreateContext(clientCode);
    try {
        // Error happens here
        await clientContext.Database.MigrateAsync();
    }
    catch (Exception ex) {
        // Error handling...
    }
}

To give some additional context I use a multitenant approach where each client has a different schema on my PostgreSQL database; I have a factory that dynamically creates contexts for each client/schema. I don't have any specific configration about collation on my model

Vorherrschende Sprache
C#
Sterne
1.8k
Forks
268
Ø Merge
2 Std. 35 Min.
Gemergte PRs (30 T.)
136

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus npgsql/efcore.pg

Alle Issues in npgsql/efcore.pg

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.