首页 > 解决方案 > TypeORM 迁移未发现任何更改

问题描述

我正在尝试使用 TypeOrm 生成迁移。当我更改实体时,它应该检测到此更改并生成新的迁移。

我收到以下错误消息:

未发现数据库架构更改 - 无法生成迁移。要创建新的空迁移,请使用“typeorm migration:create”命令

当我更改实体文件中的某些内容时,为什么会收到此错误消息?

我正在使用这个命令来运行 TypeOrm:

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

这是我的 typeormConfig.ts 文件:

import { ConnectionOptions } from "typeorm";
import * as path from "path";
import * as dotEnv from 'dotenv'

console.log(path.resolve(__dirname, 'entity/**.entity.ts'))

const result = dotEnv.config({ path: './ormconfig.env' });

if (result.error) {
  throw result.error
}

const config: ConnectionOptions = {
  type: 'mysql',
  host: process.env.TYPEORM_HOST,
  port: +process.env.TYPEORM_PORT,
  username: process.env.TYPEORM_USERNAME,
  password: process.env.TYPEORM_PASSWORD,
  database: process.env.TYPEORM_DATABASE,
  //synchronize: true,
  synchronize: false,
  // migrationsRun: false,
  entities: [path.resolve(__dirname, 'entity/**.entity.*')],
  migrations: [path.resolve(__dirname, 'migration/**')],
  cli: {
    entitiesDir: "src/entity",
    migrationsDir: "src/migration"
  }
}

export default config;

标签: node.jsmigrationtypeorm

解决方案


像这样更新实体和迁移目录链接

entities: [__dirname + '/entity/**/*.entity.ts', __dirname + '/entity/**/*.entity.js'],
migrations: [__dirname + '/migration/**/*.ts', __dirname + '/migration/**/*.js'],

它对我有用并且应该有用。


推荐阅读