【问题标题】:Object literal may only specify known properties, and 'cli' does not exist in type TypeOrmModuleOptions对象字面量只能指定已知属性,TypeOrmModuleOptions 类型中不存在 \'cli\'
【发布时间】:2022-08-24 20:30:52
【问题描述】:

我试图在我的 Nest JS 项目中与 cli 一起设置迁移,但无论我做什么,typeorm 总是对 cli 发誓。 已经很多天了,我很难过。

enter image description here

错误 TS2322:类型 \'{ 类型:\"postgres\";主机:字符串;端口:号码;用户名:字符串;数据库:字符串;密码:字符串;实体:字符串[];迁移:字符串[]; cli:{迁移目录:字符串; };额外:{字符集:字符串; };同步:假;记录:真; }\' 不可分配给类型 \'TypeOrmModuleOptions\'。 对象字面量只能指定已知属性,而 \'cli\' 类型中不存在 \'{ retryAttempts?: number;重试延迟?:数字; toRetry?: (err: any) => boolean; autoLoadEntities?:布尔值; keepConnectionAlive?: 布尔值;详细重试日志?:布尔值; } & 部分的\'。

    标签: command-line-interface nestjs typeorm


    【解决方案1】:

    如果您使用 typeorm 0.3.x,typeorm-cli 现在需要迁移路径作为命令选项。您可以删除该部分打字稿抱怨并检查此线程。 TypeORM/nest - running migrations with `useFactory`

    【讨论】:

      【解决方案2】:
      1. 你的 ORM 配置应该是 DataSource 的实例 ormconfig.ts 文件 像这样:

        导出默认新数据源({ 类型:'postgres', 主机:process.env.POSTGRES_HOST 端口:+process.env.POSTGRES_PORT, 用户名:process.env.POSTGRES_USER, 密码:process.env.POSTGRES_DB_PASSWORD, 数据库:process.env.POSTGRES_DATABASE, 实体:[__dirname + '//*.entity{.ts,.js}'], synchronize: false, migrations: [__dirname + '/migrations//*{.ts,.js}'], });

        添加到 package.json 下一个命令:

        "typeorm": "ts-node -P tsconfig.json ./node_modules/typeorm/cli.js",
        "db:drop": "yarn run typeorm schema:drop -d src/ormconfig.ts",
        "db:gen": "yarn run typeorm migration:generate src/migrations/migration -d src/ormconfig.ts",
        "db:migrate": "yarn run typeorm migration:run -- -d src/ormconfig.ts"
        

      【讨论】:

        猜你喜欢
        • 2020-11-27
        • 1970-01-01
        • 2018-09-06
        • 2021-02-18
        • 2021-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-10
        相关资源
        最近更新 更多