I need to include an email field in my User class that can be both nullable and unique. Here is the code I currently have:
user.entity.ts:
export class User
{
@Column({ name: 'email', nullable: true })
@Index('users_email_idx', { unique: true })
email!: string;
...
user-create.dto.ts:
export class UserCreateDto implements UserInputInterface {
@IsEmail()
@IsOptional()
@MaxLength(255)
email?: string;
...
When I make a creation request with "email: null", I receive a 500 error message stating "ERROR [ExceptionsHandler] null value in column "email" of relation "users" violates not-null constraint". On the other hand, if I try to send an existing email, I get another 500 error: ERROR [ExceptionsHandler] duplicate key value violates unique constraint "users_email_idx". What am I doing wrong?