Knex和Postgres连接错误-错误:角色“ admin”不存在

时间:2020-08-06 09:41:48

标签: postgresql docker-compose knex.js

我正在尝试使用knex连接到postgres db映像。但是我得到了错误: error: role "admin" does not exist

我的knexfile如下:

module.exports = {

  development: {
    debug: true,
    client: 'pg',
    connection: {
      database: process.env.POSTGRES_DB,
      user: process.env.POSTGRES_USER,
      password: process.env.POSTGRES_PASSWORD
    },

    migrations: {
      directory: __dirname + '/src/migrations'
    },
    seeds: {
      directory: __dirname + '/src/seeds'
    }
  }
};

我的docker-compose文件是:-

version: '3.1'
services:
  db:
    image: postgres
    restart: always
    volumes:
      - ./docker-data/db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRESS_USER: ${POSTGRES_USER}
      POSTGRESS_DB: ${POSTGRES_DB}
    ports:
      - 5432:5432
  pgadmin:
    depends_on:
      - db
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
    volumes:
      - ./docker-data/pgadmin-data:/root/.pgadmin
    ports:
      - 8080:80

环境变量很简单

POSTGRES_USER=admin
POSTGRES_PASSWORD=admin
POSTGRES_DB=configs
PGADMIN_DEFAULT_EMAIL=admin@admin.com
PGADMIN_DEFAULT_PASSWORD=admin

包裹详情:

  "knex": "^0.21.1",
  "pg": "^8.3.0"

我运行了命令docker-compose up,完成后我创建了迁移并发布了我运行的npx knex migrate:latest。这会导致错误

error: role "admin" does not exist
    at Parser.parseErrorMessage (/Users/test/packages/config-server/node_modules/pg-protocol/dist/parser.js:278:15)

我无法调试和修复。请帮忙。

0 个答案:

没有答案