Not null must have default value as well?

Noob question. Does a "not null" value have to have a default value? For some reason it seems like the case. This insert snippet is not working. and giving me a Object literal may only specify known properties, and email does not exist in type and Object literal may only specify known properties, and first_name does not exist in type
When I comment out phone and email from my schema/make them both nullable/add a default value it doesn't give me this error.
  async signup(dto: AuthDto) {
    const hash = await argon.hash(dto.password);
    const user = await this.dbService.db
      .insert(schema.users)
      .values({
        email: dto.email,
        phone: dto.phone
        password_hash: hash,
        first_name: 'test',
        last_name: 'user',
        role: schema.userRoleEnum.enumValues[0],
        created_at: new Date(),
      })
      .returning();
  }

schema.ts
import {
  pgTable,
  text,
  uuid,
  boolean,
  timestamp,
  pgEnum,
  varchar,
} from 'drizzle-orm/pg-core';

export const userRoleEnum = pgEnum('user_role', [
  'user',
  'admin',
  'branch_manager',
  'restaurant_owner',
]);

export const users = pgTable('users', {
  id: uuid('id').notNull().defaultRandom().primaryKey(),
  email: varchar('email', { length: 255 }).unique(),
  phone: varchar('phone', { length: 20 }).notNull().unique(),
  first_name: varchar('first_name', { length: 50 }),
  last_name: varchar('last_name', { length: 50 }),
  email_verified: boolean('email_verified').default(false),
  phone_verified: boolean('phone_verified').default(false),
  created_at: timestamp('created_at').notNull().defaultNow(),
  role: userRoleEnum('role').notNull().default('user'),
  password_hash: text('password_hash').notNull(),
});
Was this page helpful?