我正在尝试对我的项目实施 typeorm 迁移,以在所有环境中直接创建数据库和表,而无需在数据库上运行任何脚本。
"typeorm": "ts-node ./node_modules/typeorm/cli",
"migration:create": "npm run typeorm -- migration:create ./path-to-migrations/$npm_config_name",
"migration:generate": "npm run typeorm -- -d ./path-to-config/typeorm.ts migration:generate ../path-to-migrations/$npm_config_name",
"migration:run": "npm run typeorm migration:run -- -d ./path-to-config/typeorm.ts",
"migration:revert": "npm run typeorm -- -d ./path-to-config/typeorm.ts migration:revert"
我已经根据这个来源完成了我的实现:https://dev.to/amirfakour/using-typeorm-migration-in-nestjs-with-postgres-database-3c75我尝试了很多解决方案,例如将 strictPropertyInitialization 设置为tsconfig.json 等中为 false,但没有任何效果。typescript 版本“~5.1.6”。
Unable to compile TypeScript:
entity.ts:3:2 - error TS1238: Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
error TS1240: Unable to resolve signature of property decorator when called as an expression.
Argument of type 'undefined' is not assignable to parameter of type 'Object'.
要添加的一件事我认为它与 ts-node 有关,因为当我像
"typeorm": "typeorm-ts-node-esm -d path-totconfig/typeorm.ts"
那样更改 package.json 中的 typeorm 时,错误完全不同,如下所示:
Error during migration run:
Error: Unable to open file: "/path-to-config/typeorm.ts". Cannot use import statement outside a module
我也面临同样的问题