对象文字只能指定已知属性,并且CLI' Type typeormoduleoptions中不存在

发布于 2025-02-10 02:02:35 字数 545 浏览 1 评论 0原文

我正在尝试将Nest JS项目中的迁移与CLI一起设置,但是无论我做什么,TypeOmm始终在CLI上发誓。 已经有很多天了,我很难过。

在此处输入图像描述

错误ts2322:type'{type'{type'{type:“ postgres”;主机:字符串;端口:号码;用户名:字符串;数据库:字符串;密码:字符串;实体:字符串[];迁移:字符串[]; CLI:{MigrationsDir:String; };额外:{charset:string; };同步:false;记录:是的; }'不能分配给'TypeModuleOptions'。 对象文字只能指定已知属性,而“ cli”在type'{retryAttEmpts中不存在?:number; retrydelay?:编号; toretry?:( err:no)=>布尔;自动加载?:布尔值; keepconnectional? verboseretrylog?:布尔值; }&部分的'。

I'm trying to set up migrations in my Nest JS project along with the cli, but no matter what I do, typeorm always swears on the cli.
It's been many days and I'm stumped.

enter image description here

error TS2322: Type '{ type: "postgres"; host: string; port: number; username: string; database: string; password: string; entities: string[]; migrations: string[]; cli: { migrationsDir: string; }; extra: { charset: string; }; synchronize: false; logging: true; }' is not assignable to type 'TypeOrmModuleOptions'.
Object literal may only specify known properties, and 'cli' does not exist in type '{ retryAttempts?: number; retryDelay?: number; toRetry?: (err: any) => boolean; autoLoadEntities?: boolean; keepConnectionAlive?: boolean; verboseRetryLog?: boolean; } & Partial'.

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

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

发布评论

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

评论(2

谁许谁一生繁华 2025-02-17 02:02:35

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

If you use typeorm 0.3.x, typeorm-cli needs migration path as a command option now. You can delete that part typescript complains and check this thread. TypeORM/nest - running migrations with `useFactory`

若有似无的小暗淡 2025-02-17 02:02:35
  1. 您ORM配置应该是DataSource的实例
    ormconfig.ts文件
    像这样:

    导出默认新dataSource({
    类型:“ 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}'],
    同步:false,
    迁移:[__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"
  1. You ORM config should be instance of DataSource
    ormconfig.ts file
    like this:

    export default new DataSource({
    type: 'postgres',
    host: process.env.POSTGRES_HOST
    port: +process.env.POSTGRES_PORT,
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_DB_PASSWORD,
    database: process.env.POSTGRES_DATABASE,
    entities: [__dirname + '//*.entity{.ts,.js}'],
    synchronize: false,
    migrations: [__dirname + '/migrations/
    /*{.ts,.js}'],
    });

add to package.json next commands:

"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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文