javascript - 如何在 typeorm 中指定 ormcofig.js
问题描述
我有typescript
项目并在项目中创建以下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
然后我尝试了以下typeorm
migration
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"
错在哪里?我该如何解决?
谢谢
解决方案
迁移文件是生成根目录而不是指定的迁移目录。
cli: { migrationsDir: "dist/migrations/develop" }
您可以通过添加到文件来设置生成迁移的目录ormconfig.js
。
该migrations
属性仅指定 typeorm 将从何处加载迁移。
查看文档
ormconfig.js 似乎没有指定。
我不知道你的意思是什么,你能详细说明一下吗?
推荐阅读
- python - 使用 Python 合并 csv 文件
- jquery - Sharepoint 2013 预览窗格视图 - 搜索不起作用
- php - 在 laravel 中创建一个 mongoDB 连接
- intellij-idea - 当intellij打开而不关闭intellij时如何删除node_modules?win 10 - 文件夹正在使用中
- botframework - 无法使用 Direct Line 将 (500) 连接到机器人框架
- laravel - 如何手动将 UploadedFile 添加到 $request->files
- ios - 对不同的函数值使用相同的 swift UIlabels
- java - 如何正确使用 SLF4J 或切换到 java util logging
- firebase - 错误:未为类型“DocumentSnapshot”定义运算符“[]”
- google-sheets - 带有包含字符和 OR 逻辑的文本的 COUNTIF/COUNTIFS 无法按预期工作