Search code examples
mysqlnode.jsmariadbtypeorm

TypeORM MariaDB Primary Key as UUID


Having a really strange issue with TypeORM and MariaDB. I have two entities with UUIDs as the primary key. The Companies entity is working fine as it scaffolds the schema as CHAR but the users table is being instantiated as an auto increment INT.

User Entity

@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;
}

Companies Entity

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

  @Column()
  name: string;

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

Config

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

Users Table Screenshot

Companies Table Screenshot

Find it really strange, is it because I'm using MariaDB instead of straight MySQL?


Solution

  • Okay looks like I fixed it, really odd one. Looks like something was cached incorrectly. Deleted dist folder and node modules. reinstalled and total recompile. Fixed...