【问题标题】:TypeORM config not reloadedTypeORM 配置未重新加载
【发布时间】:2021-06-13 16:08:29
【问题描述】:

在旧配置中,我使用 mssql 作为数据库,

ormconfig.json:

{
  "type": "mssql",
  "host": "localhost",
  "port": "1433",
  "username": "sa",
  "password": "*******",
  "database": "onboarding",
  "synchronize": true ,
  "logging": true,
  "entities": ["./src/**/*.entity.ts", "./dist/**/*.entity.js"]
}

然后我将配置更改为使用 postgres

{
  "type": "postgres",
  "host": "localhost",
  "port": "5432",
  "username": "root",
  "password": "*******",
  "database": "onboarding",
  "synchronize": true ,
  "logging": true,
  "entities": ["./src/**/*.entity.ts", "./dist/**/*.entity.js"]
}

然后我卸载了mssql驱动并通过npm添加了postgres驱动,重启我的程序后,TypeOrm一直在询问mssql

[Nest] 40351   - 06/13/2021, 11:01:49 PM   [TypeOrmModule] Unable to connect to the database. Retrying (5)... +3005ms    

DriverPackageNotInstalledError: SQL Server package has not been found installed. Try to install it: npm install mssql --save

有人知道为什么没有加载新配置吗?我试过 npm clean 缓存,删除 node_modules 和 dist 文件夹,但还是不行。

【问题讨论】:

    标签: node.js nestjs typeorm node.js-typeorm


    【解决方案1】:

    如果有人遇到和我一样的问题,原来 typeorm 会忽略 ormconfig.json 上的设置,因为我的 .env 文件中有一个名为 TYPEORM_URL 的变量,任何与 .env 上的 typeorm 相关的设置都会自动加载通过键入 orm 并替换 ormconfig.json 中的值(我认为我们需要使用 process.env 手动解析它)。

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 2014-02-13
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 2015-03-28
      • 2013-10-03
      相关资源
      最近更新 更多