typeorm: auto generated UUID in postgresql typeorm: auto generated UUID in postgresql typescript typescript

typeorm: auto generated UUID in postgresql


Try:

@PrimaryGeneratedColumn("uuid")id: string;

Also, if you don't need a primary column, but need to generate uuid sequence, you can try this:

@Column()@Generated("uuid")uuid: string;


As of Typeorm version 0.1.16, the decorator @PrimaryGeneratedColumn supports uuid for all databases.

Usage:

@Entity()class MyClass {  @PrimaryGeneratedColumn('uuid')  id: string;}

If your version of Postgres doesn't already include uuid-ossp (used to generate the UUID), you can install it using create extension "uuid-ossp";.


for me, I use this shape

@PrimaryGeneratedColumn('uuid')  id: string

we can use another shapeyou should install the UUID package

@PrimaryColumn() id:stringand used the @BeforeInsert() genarate(){ this.id=uuid()