自从在 PostgreSQL 中使用某些登录/角色后,EF Core 更新不起作用

问题描述 投票:0回答:1

我尝试更新现有的数据库(代码优先)。表

__EFMigrationsHistory
已经存在,它应该只是更新。

这是我在对数据库进行一些更改以创建

ReadOnlyUser
后遇到的错误。

注意(法语到英语)

  • 法语:42P07:la 关系 « __EFMigrationsHistory » 存在 déjà
  • 英语:42P07:关系“__EFMigrationsHistory”已经存在

在我看来,根据第一个选择,并且因为表“__EFMigrationsHistory”已经存在,所以第一个参数“1”听起来像是没有被适当的值替换。我一生中从未见过“SELECT 1”,这对我来说听起来很奇怪。难道是没有找到合适的数据库/模式?我可以毫无问题地从 DBeaver 中进行任何选择。我不明白。

错误:

PM> update-database -Context MicroReseauDbContext
Build started...
Build succeeded.
2023-11-06 17:13:56.987 CoreEventId.SensitiveDataLoggingEnabledWarning[10400] (Microsoft.EntityFrameworkCore.Infrastructure) 
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
    SELECT 1 FROM pg_catalog.pg_class c
    JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
    WHERE n.nspname='public' AND
          c.relname='__EFMigrationsHistory'
)
    SELECT 1 FROM pg_catalog.pg_class c
    JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
    WHERE n.nspname='public' AND
          c.relname='__EFMigrationsHistory'
)
Failed executing DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE "__EFMigrationsHistory" (
    migration_id character varying(150) NOT NULL,
    product_version character varying(32) NOT NULL,
    CONSTRAINT pk___ef_migrations_history PRIMARY KEY (migration_id)
);
fail: 2023-11-06 17:13:57.495 RelationalEventId.CommandError[20102] (Microsoft.EntityFrameworkCore.Database.Command) 
      Failed executing DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE "__EFMigrationsHistory" (
          migration_id character varying(150) NOT NULL,
          product_version character varying(32) NOT NULL,
          CONSTRAINT pk___ef_migrations_history PRIMARY KEY (migration_id)
      );
Npgsql.PostgresException (0x80004005): 42P07: la relation « __EFMigrationsHistory » existe déjà
   at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|234_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
  Exception data:
    Severity: ERREUR
    SqlState: 42P07
    MessageText: la relation « __EFMigrationsHistory » existe déjà
    File: heap.c
    Line: 1202
    Routine: heap_create_with_catalog
42P07: la relation « __EFMigrationsHistory » existe déjà

更新2023年11月7日,我刚刚成功更新了另一个数据库(完全相同的过程),唯一的区别是在这种情况下我没有在该数据库上创建“只读”用户。当我创建“只读”用户时,我删除了对数据库的“公共”访问权限并直接由用户设置权限。

c# postgresql schema roles ef-core-3.1
1个回答
0
投票

我通过向用于连接数据库的用户添加“超级用户”权限来解决我的问题。已被删除。

© www.soinside.com 2019 - 2024. All rights reserved.