node.js - 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;
解决方案
像这样更新实体和迁移目录链接
entities: [__dirname + '/entity/**/*.entity.ts', __dirname + '/entity/**/*.entity.js'],
migrations: [__dirname + '/migration/**/*.ts', __dirname + '/migration/**/*.js'],
它对我有用并且应该有用。
推荐阅读
- r - 在 plotly 和 ggplot2 中放置相同的颜色
- swift - Xcode 11 动作编辑器?如何调用?
- authentication - JMeter 中用于 Microsoft 登录的 Autorization Bearer 的解决方法(适用于具有特定组织服务帐户的单页应用程序)
- tensorflow - 张量流问题,cudnn
- reactjs - 反应无限滚动
- python-3.x - smote.fit_sample() 和 smote.fit_resample() 的区别
- html - HTML 电子邮件被空白包围(仅在移动设备上)
- c# - C# 反射 - 缺少字段?
- opengl - 无法在 Jupyerhub 上使用 opengl 多重映射
- javascript - 是否可以连接方法,如排序。shift、pop、push 和 unshift