- 创建自动生成的列
创建自动生成的列
假设你希望 id 列自动生成(这称为 auto-increment/sequence/serial/generated identity column)。为此你需要将@PrimaryColumn
装饰器更改为@PrimaryGeneratedColumn
装饰器:
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;
}