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

Aberta
#3,589 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
csharp, postgresql
Domínio
databases

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
C#
Estrelas
1.8k
Forks
268
Merge médio
2h 35min
PRs com merge (30d)
136

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de npgsql/efcore.pg

Todas as issues de npgsql/efcore.pg

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.