Creating an auto generated column

Creating an auto generated column

Now, let‘s say you want your id column to be auto-generated (this is known as auto-increment / sequence / serial / generated identity column).To do that, you need to change the @PrimaryColumn decorator to a @PrimaryGeneratedColumn decorator:

import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";

@Entity()
export class Photo {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;

    @Column()
    description: string;

    @Column()
    filename: string;

    @Column()
    views: number;

    @Column()
    isPublished: boolean;
}