Nullable columns doesn't show up while doing inserts

This is my database schema
export const users = pgTable('users', {
id: uuid('id').defaultRandom().primaryKey(),
name: varchar('name', { length: 255 }).notNull(),
email: varchar('email', { length: 255 }).notNull().unique(),
password: varchar('password', { length: 255 }).notNull(),
email_verified_at: timestamp('email_verified_at'),
created_at: timestamp('created_at').defaultNow(),
updated_at: timestamp('updated_at')
.defaultNow()
.$onUpdate(() => new Date()),
});

export const tokenTypes = pgEnum('token_types', [
'EMAIL_VERIFICATION',
'PASSWORD_RESET',
'ORGANIZATION_INVITE',
]);

export const tokens = pgTable('tokens', {
id: uuid('id').defaultRandom().primaryKey(),
type: tokenTypes('type').notNull(),
token: varchar('token', { length: 255 }).notNull().unique(),
user_id: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }),
organization_id: uuid('organization_id').references(() => organizations.id),
expires_at: timestamp('expires_at'),
});
export const users = pgTable('users', {
id: uuid('id').defaultRandom().primaryKey(),
name: varchar('name', { length: 255 }).notNull(),
email: varchar('email', { length: 255 }).notNull().unique(),
password: varchar('password', { length: 255 }).notNull(),
email_verified_at: timestamp('email_verified_at'),
created_at: timestamp('created_at').defaultNow(),
updated_at: timestamp('updated_at')
.defaultNow()
.$onUpdate(() => new Date()),
});

export const tokenTypes = pgEnum('token_types', [
'EMAIL_VERIFICATION',
'PASSWORD_RESET',
'ORGANIZATION_INVITE',
]);

export const tokens = pgTable('tokens', {
id: uuid('id').defaultRandom().primaryKey(),
type: tokenTypes('type').notNull(),
token: varchar('token', { length: 255 }).notNull().unique(),
user_id: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }),
organization_id: uuid('organization_id').references(() => organizations.id),
expires_at: timestamp('expires_at'),
});
When i try to do insert on any nullable fields it doesn't show up in insert types. Let's say while creating tokens user_id is nullable but i want to insert the user_id when creating token if i type user_id in values it shows typescript error. If i add .notNull() in the user_id foreign key it shows up in the insert. does anyone has this issue?
1 Reply
Krunal Shah
Krunal ShahOP4mo ago
It's a bug when you have strict set to false in tsconfig. https://github.com/drizzle-team/drizzle-orm/issues/2694
GitHub
[BUG]: Nullable columns do not exist in insert(table).values() · I...
What version of drizzle-orm are you using? 0.32.1 What version of drizzle-kit are you using? 0.23.0 Describe the Bug const files = pgTable("files", { id: uuid("id").primaryKey()...
Want results from more Discord servers?
Add your server