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:

  1. import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";
  2. @Entity()
  3. export class Photo {
  4. @PrimaryGeneratedColumn()
  5. id: number;
  6. @Column()
  7. name: string;
  8. @Column()
  9. description: string;
  10. @Column()
  11. filename: string;
  12. @Column()
  13. views: number;
  14. @Column()
  15. isPublished: boolean;
  16. }