【问题标题】:TypeORM generates migrations with db nameTypeORM 生成带有数据库名称的迁移
【发布时间】:2021-12-06 10:40:36
【问题描述】:

我需要使用 TypeORM 生成迁移,它使用以下命令完成:

npm run typeorm migration:generate -n test

但问题是它会生成包含数据库名称的迁移

 await queryRunner.query(`CREATE TABLE \`testdb\`.\`lbs_user\` (\`id\` char(36) NOT ...

我可以以某种方式删除“testdb”吗?

这是配置文件

{
    "type": "mysql",
    "host": conf.env.migrationDatabase.host,
    "port": conf.env.migrationDatabase.port,
    "username": conf.env.migrationDatabase.username,
    "password": conf.env.migrationDatabase.password,
    "database": conf.env.migrationDatabase.dbName, //the database name is -> testdb
    "entityPrefix": conf.env.database.entityPrefix,
    "synchronize": false,  
    "migrationsTableName": `${conf.env.database.entityPrefix}migrations`,
    "entities": ["src/modules/db/entities/**/*.entity.ts"],
    "migrations": ["src/migrations/**/*.ts"],
    "cli": {      
        "migrationsDir": "src/migrations",
    }
}

实体声明:

@Entity("user")
export class UserEntity {
    @PrimaryColumn({ generated: "uuid" })
    id: string;

    @Column({
        unique: true,
    })
    email: string;

【问题讨论】:

  • 你能添加你的实体类吗?只是类/实体声明,而不是所有字段的定义。我看到你的配置文件中有"entityPrefix": conf.env.database.entityPrefix, - 这会影响它吗?
  • 感谢您的回复。添加了实体。我检查了“entityPrefix”,不是这样,它只是在表格前面添加了前缀。在这种情况下“lbs_”
  • 但我想您可以手动编辑迁移,对吧?无论如何,这不应该对你造成问题,对吧?
  • 当然可以,但这不是我想要的方式。想要确保无论生成什么,它都可以在没有任何人工干预的情况下工作

标签: database migration schema typeorm generate


【解决方案1】:

最后,看来我使用的是旧版本的 typeorm。升级到 0.2.38 版本,不再生成数据库名称。

【讨论】:

    猜你喜欢
    • 2019-11-17
    • 1970-01-01
    • 2021-04-29
    • 2021-10-17
    • 2021-10-26
    • 2016-06-09
    • 2022-11-14
    • 2021-08-02
    • 2021-05-23
    相关资源
    最近更新 更多