首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Typeorm不将迁移保存在正确的文件夹中。

Typeorm不将迁移保存在正确的文件夹中。
EN

Stack Overflow用户
提问于 2022-06-03 00:57:46
回答 1查看 533关注 0票数 0

当使用Nest.js使用TypeORM启动项目时,我使用存档ormconfig.json和下面的命令。

但是在终端中使用命令npm运行迁移:创建-n测试项目将迁移存档保存在根文件夹中,而不保存在ormconfig.json中的配置文件夹后面

错误在哪里?如何使迁移存档转到typeorm/迁移文件夹?

代码语言:javascript
运行
复制
    "type": "mysql",
    "host": "localhost",
    "port": 3306,
    "username": "root",
    "password": "root",
    "database": "ferrari",
    "synchronize": true,
    "logging": false,
    "entities": [
        "typeorm/entity/**/*.ts"
    ],
    "migrations": [
        "typeorm/migration/**/*.ts"
    ],
    "subscribers": [
        "typeorm/subscriber/**/*.ts"
    ],
    "cli": {
        "entitiesDir":"typeorm/entity",
        "migrationsDir": "typeorm/migration",
        "subscribersDir":"typeorm/subscriber"
    }
}

这是结构目录

代码语言:javascript
运行
复制
-src
-typeorm
   -migrations
ormconfig.json
package.json
EN

回答 1

Stack Overflow用户

发布于 2022-06-03 12:20:18

在搜索了这个问题之后,我发现了下面的解决方案:

我改变了每一个omrconfig.jsonomrconfig.ts和这个模型

代码语言:javascript
运行
复制
export default {
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: 'root',
  database: 'test',
  synchronize: false,
  logging: true,
  "entities": [
      "src/typeorm/**/*.ts"
  ],
  "migrations": [
       "typeorm/migrations/**/*.ts"
  ],
  "subscribers": [
      "src/subscriber/**/*.ts"
  ],
  "cli": {
      "entitiesDir": "src/typeorm",
      "migrationsDir": "typeorm/migrations",
      "subscribersDir": "src/typeorm"
  }
};

然后,我安装了typeorm CLI全局

npm i -g typeorm

并在package.json中添加两个脚本,第一个脚本是:

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

第二个问题是:

"migrate:create": "typeorm migration:create \"./typeorm/migrations/"

因此,我设法使用终端命令将迁移保存在所选文件夹中的typeorm/迁移中。

npm run migrate:create -n {migrationName}

这个typeORM版本是0.3.6

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72483698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档