Ben Awad Vid 教程问题与 Npx Micro-Worm migration:create

Ben Awad vid tutorial problemwith npx mikro-orm migration:create

我按照教程一步一步来,当我到达 运行 npx mikro-orm migration:create 的部分时,我得到了这个错误

TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received null

    at prepareSecretKey (internal/crypto/keys.js:322:11)
    at new Hmac (internal/crypto/hash.js:113:9)
    at Object.createHmac (crypto.js:147:10)
    at createHMAC (C:\lireddit-server\node_modules\pg\lib\sasl.js:133:17)
    at Hi (C:\lireddit-server\node_modules\pg\lib\sasl.js:137:13)
    at Object.continueSession (C:\lireddit-server\node_modules\pg\lib\sasl.js:32:24)
    at Client._handleAuthSASLContinue (C:\lireddit-server\node_modules\pg\lib\client.js:248:10)
    at Connection.emit (events.js:314:20)
    at Connection.EventEmitter.emit (domain.js:483:12)
    at C:\lireddit-server\node_modules\pg\lib\connection.js:109:12
    at Parser.parse (C:\lireddit-server\node_modules\pg-protocol\src\parser.ts:102:9)
    at Socket.<anonymous> (C:\lireddit-server\node_modules\pg-protocol\src\index.ts:7:48)
    at Socket.emit (events.js:314:20)
    at Socket.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:298:12)
    at readableAddChunk (_stream_readable.js:273:9)```

I can't find any solution on google, and the tut doesn't point out how to login to postgresql on the app

您缺少一些配置,很可能是 userpassword 字段。这是相关问题:

https://github.com/mikro-orm/mikro-orm/issues/866

如果您不提供它们,MikroORM 将为给定的驱动程序选择默认值,即 postgres 用户和空密码 - 您的 postgres 安装显然没有该用户的空密码。

如果您正在使用 docker 创建 postgres 服务器,您可以通过以下方式让它接受空 pws:

  postgre:
    image: postgres:12.4
    ports:
      - 5432:5432
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust   <-- here

您似乎没有指定要在 MikroORM.init.

中传递的对象的 passworduser 属性

这应该有效

export default {
  entities: [Entity],
  dbName: "yourDatabaseName",
  type: "postgresql",
  user: "yourUserName",
  password: "yourPassword"
} as Parameters<typeof MikroORM.init>[0];