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

Ouverte
#3,589 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
csharp, postgresql
Domaine
databases

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
C#
Étoiles
1.8k
Forks
268
Merge moyen
2 h 35 min
PR mergées (30 j)
136

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de npgsql/efcore.pg

Toutes les issues de npgsql/efcore.pg

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.