I have one BaseEntity which is common for multiple modules. so I have created some common column in this entity class. all the classes will extend this class.
export abstract class BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
createdAt: Date;
@UpdateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
modifiedAt: Date;
@DeleteDateColumn({ type: 'timestamp' })
deletedAt: Date;
}
my Certificate class is extending BaseEntity. now I want to generate value of certificateNo automatically.
Entity({ name: 'certificate' })
export class Certificate extends BaseEntity {
@ApiProperty()
@Generated('increment')
certificateNo: string;
@ApiProperty()
@Column({ type: 'varchar', length: 100 })
requestStatus: RequestStatus;
@ApiProperty()
@Column({ type: 'varchar', length: 100 })
sponser: string;
}
in the certificateNo column as soon as I put @Column() decorator it gives error. otherwise this column does not get created in database. DB is postgres.
@ApiProperty()
@Column() //if I write @Column() error comes. If I dont write ,column not created in DB
@Generated('increment')
certificateNo: string;
Error is:-
[Nest] 24080 - 12/01/2021, 12:59:35 PM [ExceptionHandler] syntax error at or near "NOT" +4ms
QueryFailedError: syntax error at or near "NOT"

You should specify a correct column type for the "certificateNo" property. See below: