Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript typeorm迁移api不生成自动代码_Typescript_Typeorm - Fatal编程技术网

Typescript typeorm迁移api不生成自动代码

Typescript typeorm迁移api不生成自动代码,typescript,typeorm,Typescript,Typeorm,您好,我在自动生成迁移代码时遇到问题。 基本上,我遵循一些教程,当更改列时,迁移代码会自动生成,但这不会发生在我身上 我在package.json上的脚本: "scripts": { "commit": "git-cz", "build": "babel src --extensions \".js,.ts\" --out-dir dist --copy-files

您好,我在自动生成迁移代码时遇到问题。 基本上,我遵循一些教程,当更改列时,迁移代码会自动生成,但这不会发生在我身上

我在package.json上的脚本:

  "scripts": {
    "commit": "git-cz",
    "build": "babel src --extensions \".js,.ts\" --out-dir dist --copy-files --no-copy-ignored",
    "start": "node dist/server.js",
    "dev:server": "ts-node-dev --inspect --respawn --transpile-only --ignore-watch node_modules -r tsconfig-paths/register src/shared/infra/http/server.ts",
    "test": "jest",
    "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
    "lint": "eslint --fix"
  },
我的实体(我将random列更改为其他名称,以使用自动代码测试生成迁移)

users.entity.ts:

import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { SharedProp } from './sharedProp.helper';

@Entity({ name: 'users' })
export class User extends SharedProp {
  constructor(isActive: boolean, login: string, password: string) {
    super();
    this.isActive = isActive;
    this.login = login;
    this.password = password;
  }
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'login', nullable: false })
  login: string;

  @Column({ nullable: false })
  password: string;

  @Column({ name: 'is_active', nullable: false })
  isActive: boolean;
}
这是我的ormconfig:

const rootDir = process.env.NODE_ENV === 'development' ? 'src' : 'build/src';

module.exports = {
  type: 'postgres',
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  username: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME,
  synchronize: false,
  logging: false,
  entities: [rootDir + '/entities/**/*.{js,ts}'],
  migrations: [rootDir + '/migrations/*.{js,ts}'],
  subscribers: [rootDir + '/subscribers/**/*.{js,ts}'],
  seeds: [rootDir + '/migrations/seeds/**/*.{js,ts}'],
  factories: [rootDir + '/migrations/factories/**/*.{js,ts}'],
  cli: {
    entitiesDir: `${rootDir}/entities`,
    migrationsDir: `${rootDir}/migration`,
    subscribersDir: `${rootDir}/subscriber`,
  },
};
我启动了服务器,将列密码更改为passwords并执行了以下命令:

yarn typeorm -- migration:create -n Password 
yarn run v1.22.4
warning From Yarn 1.0 onwards, scripts don't require "--" for options to 
be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ node --require ts-node/register ./node_modules/typeorm/cli.js migration:create -n Password
Migration G:\emasati_stockcontrol/src/migration/1595290975334-Password.ts has been generated successfully.
Done in 1.86s.
但由于某些原因,它不会在迁移中自动生成alter表:

export class Password1595290975334 implements MigrationInterface {

    public async up(queryRunner: QueryRunner): Promise<void> {
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
    }

}
导出类密码1595290975334实现迁移接口{
公共异步启动(queryRunner:queryRunner):承诺{
}
公共异步关闭(queryRunner:queryRunner):承诺{
}
}

尝试添加到package.json

"scripts": {
   ...
   "migration:generate": "yarn run typeorm migration:generate -n"
}
并执行以下命令:

yarn run migration:generate -- [MigrationNameWithoutBrackets]