我试着用ormconfig.json个这样的

{
  "name": "default",
  "type": "postgres",
  "host": "ip-is-here",
  "port": 5432,
  "username": "name",
  "password": "12345",
  "database": "db1",
  "synchronize": false,
  "logging": false,
  "entities": ["dist/storage/**/*.js"],
  "migrations": ["dist/storage/migrations/**/*.js"],
  "cli": {
    "entitiesDir": "src/storage",
    "migrationsDir": "src/storage/migrations"
  }
}

via yarn typeorm migration:run
But get an error:

Missing required argument: dataSource

我该怎么办?

推荐答案

TypeForm放弃了使用ormconfig.更晚版本的json.你应该使用新的轴.创建ormconfig.ts并为您的数据库指定选项,在我的例子中,其外观如下:

    export const connectionSource = new DataSource({
        migrationsTableName: 'migrations',
        type: 'postgres',
        host: 'localhost',
        port: 5432,
        username: 'user',
        password: 'pass',
        database: 'somehealthchecker',
        logging: false,
        synchronize: false,
        name: 'default',
        entities: ['src/**/**.entity{.ts,.js}'],
        migrations: ['src/migrations/**/*{.ts,.js}'],
        subscribers: ['src/subscriber/**/*{.ts,.js}'],
    });

运行连接后

    await connectionSource.initialize();

然后你可以通过使用

    const myRepo = connectionSource.getRepository(SomeEntity)

还有你的脚本.json应该类似于此示例

"migration:generate": "./node_modules/.bin/ts-node ./node_modules/.bin/typeorm migration:generate -d src/modules/config/ormconfig.ts",
"migration:up": "./node_modules/.bin/ts-node ./node_modules/.bin/typeorm migration:run -d src/modules/config/ormconfig.ts",
"migration:down": "./node_modules/.bin/ts-node ./node_modules/.bin/typeorm migration:revert -d src/modules/config/ormconfig.ts",

在命令之后,只需在控制台中给出迁移的名称,而不使用-n选项

Node.js相关问答推荐

Windows上使用ES6+的OpenAPI规范的Express服务器不接受嵌套路由'

在我的Next.js应用程序中没有正确设置Process.env.NODE_ENV

为什么 Cors 在 NodeJS 中不起作用

在 Docker 容器内创建一个 cron 作业(job)来执行 run.js 文件中的函数

为什么我的 Node.js 应用程序在登录时无法正确验证密码(使用 Passport-local 和 bcryptjs)?

如何在套接字对象中存储或添加数据?

我正在try 在公共目录中使用 Express.js 项目部署 Angular 静态构建

使用 NPM 三个 mocha+typescript 进行测试

为什么 FastAPI 需要 Web 服务器(即 Nginx)而不是 Express API?

当我try 从本地主机发布新产品时收到错误消息

错误:找不到模块'C:\Users\nguye\AppData\Local\nodejs\node_modules\npm\bin\npm-cli.js'

aws cdk 2.0 init 应用程序无法构建更漂亮的问题,这来自 jest-snapshot

在 gatsby 中安装软件包时不推荐使用的错误

我可以向NPM添加调试脚本吗?

什么使用/尊重 .node-version 文件?

容器之间的 Docker HTTP 请求

为什么我们要为 Angular 2.0 安装 Node.js?

npm install 给出警告,npm audit fix 不起作用

使用 Node.js 我得到错误:EISDIR,读取

大型项目的 NodeJS vs Play 框架