【问题标题】:TypeORM MariaDB Primary Key as UUIDTypeORM MariaDB 主键为 UUID
【发布时间】:2021-10-21 15:48:13
【问题描述】:

TypeORM 和 MariaDB 有一个非常奇怪的问题。我有两个以 UUID 作为主键的实体。 Companies 实体工作正常,因为它将架构构建为 CHAR,但用户表被实例化为自动增量 INT。

用户实体

@Entity()
export class User {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  firstname: string;

  @Column()
  lastname: string;

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

  @Column()
  password: string;

  @ManyToOne(() => Company, (company) => company.users)
  company: Company;
}

公司实体

@Entity()
export class Company {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  name: string;

  @OneToMany(() => User, (user) => user.company)
  users: User[];
}

配置

const config: MysqlConnectionOptions = {
  type: 'mariadb',
  ....
  entities: ['dist/src/**/*.entity.js'],
  synchronize: true,
};

Users Table Screenshot

Companies Table Screenshot

觉得很奇怪,是不是因为我使用的是 MariaDB 而不是直接的 MySQL?

【问题讨论】:

    标签: mysql node.js mariadb typeorm


    【解决方案1】:

    好吧,看来我修好了,真的很奇怪。看起来有些东西被错误地缓存了。删除了 dist 文件夹和节点模块。重新安装并重新编译。固定...

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多