实体框架+后GIS GET OMIGRATION失败了错误:28000:角色“ my_username”不存在

发布于 2025-02-12 22:47:39 字数 1750 浏览 0 评论 0 原文

我有一个使用以下 docker-compose compose file

version: '3.9'
volumes:
  dbbackups:
  postgis-data:

services:

  db:
    image: kartoza/postgis:14-3.2
    volumes:
      - postgis-data:/var/lib/postgresql
      - dbbackups:/backups
    environment:
      # If you need to create multiple database you can add coma separated databases eg gis,data
      - POSTGRES_DB=my_db
      - POSTGRES_USER=my_username
      - POSTGRES_PASS=my_password
      - ALLOW_IP_RANGE=0.0.0.0/0
      # Add extensions you need to be enabled by default in the DB. Default are the five specified below
      - POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology,postgis_raster,pgrouting
    ports:
      - "25432:5432"
    restart: on-failure
    healthcheck:
      test: "exit 0"

我有一个配置为使用此数据库的ASP.NET Core Web API项目。在 program.cs 中:

builder.Services.AddDbContext<PerceptionAnnotationServerContext>(options =>
    options.UseNpgsql("Host=localhost;Port=25432;Database=my_db;Username=my_username;Password=my_password"));

如果我做 get-emigration add-emigration 然后更新数据库从VS 2022 Pack Manager控制台,我会收到错误:

访问数据库时发生了错误。继续没有数据库提供的信息。错误:28000:角色“ my_username”不存在

我最初发现如何添加用户。但是,使用pgadmin进行检查表明“ my_username”已经存在,并且可以访问“ my_db”。

有什么想法吗?

I have a postgis database running using the following docker-compose file:

version: '3.9'
volumes:
  dbbackups:
  postgis-data:

services:

  db:
    image: kartoza/postgis:14-3.2
    volumes:
      - postgis-data:/var/lib/postgresql
      - dbbackups:/backups
    environment:
      # If you need to create multiple database you can add coma separated databases eg gis,data
      - POSTGRES_DB=my_db
      - POSTGRES_USER=my_username
      - POSTGRES_PASS=my_password
      - ALLOW_IP_RANGE=0.0.0.0/0
      # Add extensions you need to be enabled by default in the DB. Default are the five specified below
      - POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology,postgis_raster,pgrouting
    ports:
      - "25432:5432"
    restart: on-failure
    healthcheck:
      test: "exit 0"

I have an ASP.Net Core Web API project configured to use this database. In Program.cs:

builder.Services.AddDbContext<PerceptionAnnotationServerContext>(options =>
    options.UseNpgsql("Host=localhost;Port=25432;Database=my_db;Username=my_username;Password=my_password"));

If I do Get-Migration or Add-Migration then Update-Database from the VS 2022 pack manager console, I get the error:

An error occurred while accessing the database. Continuing without the information provided by the database. Error: 28000: role "my_username" does not exist

I initially found this answer on how to add the user. However checking with pgAdmin shows that the role "my_username" already exists and has access to "my_db".

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

檐上三寸雪 2025-02-19 22:47:39

我忘记了添加到DB上下文中:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql("Host=localhost;Port=25432;Database=my_db;Username=my_username;Password=my_password");
    }

I had forgotten to add to the db context:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql("Host=localhost;Port=25432;Database=my_db;Username=my_username;Password=my_password");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文