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

オープン
#3,589 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp, postgresql
領域
databases

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
C#
スター
1.8k
フォーク
268
平均マージ
2時間 35分
マージ済み PR(30日)
136

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npgsql/efcore.pg のほかの issue

npgsql/efcore.pg の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。