【问题标题】:How to specify ormcofig.js in typeorm如何在 typeorm 中指定 ormcofig.js
【发布时间】:2020-09-17 14:23:19
【问题描述】:

我有typescriptproject 并在项目中创建以下ormconfig.js 文件。

module.exports = {
  type: 'mysql',
  host: 'db',
  port: 3306,
  username: 'root',
  password: 'test',
  database: 'db',
  entities: ['dist/entities/**/*.entity.js'],
  migrations: ['dist/migrations/develop/**/*.js'],
  logging: true,
};

在我的项目下面tsconfig.json 也创建在项目目录中。

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }
}

之后

npm run build

.ts被编译到以下目录。

-dist
  -migrations
    -develop
  -entities
    -entity1.js
    -entity2.js

然后我尝试关注typeormmigration

npm run typeorm migration:create -- -n migration

生成迁移文件的根目录不是指定的迁移目录。

ormconfig.js 好像没有指定。

package.json 正在关注

"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config ormconfig.js"

错在哪里? 我该如何解决?

谢谢

【问题讨论】:

    标签: javascript node.js typescript nestjs typeorm


    【解决方案1】:

    迁移文件是生成根目录而不是指定的迁移目录。

    您可以通过将cli: { migrationsDir: "dist/migrations/develop" } 添加到您的ormconfig.js 文件来设置生成迁移的目录。
    migrations 属性仅指定 typeorm 将从何处加载迁移。
    请参阅 documentation

    ormconfig.js 好像没有指定。

    我不知道你的意思是什么,你能详细说明一下吗?

    【讨论】:

      猜你喜欢
      • 2019-02-10
      • 1970-01-01
      • 2019-03-26
      • 2022-07-07
      • 2022-07-25
      • 2019-12-25
      • 2019-06-03
      • 2022-08-05
      • 2021-09-25
      相关资源
      最近更新 更多