how to set default null to an int column

I want the parentId to have the default Null, how to do that
export const comments = mysqlTable(
'comments',
{
id: serial('id').primaryKey(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
});
export const comments = mysqlTable(
'comments',
{
id: serial('id').primaryKey(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
});
8 Replies
Thogn
ThognOP14mo ago
It seems like it's not
No description
tacomanator
tacomanator14mo ago
are you sure you're not passing a blank string value when inserting? what happens if you add
.default(sql`NULL`)
.default(sql`NULL`)
to the column def?
Thogn
ThognOP14mo ago
i added this .default(sqlNULL). no type error occurs, im pretty sure that im not passing a blank string value,
Thogn
ThognOP14mo ago
One more thing that, createAt has Null default where i shouldnt be. createdAt: timestamp('created_at').default(sqlCURRENT_TIMESTAMP),
No description
tacomanator
tacomanator14mo ago
Did you check the log to see the SQL being generated for insert? https://orm.drizzle.team/docs/goodies#logging
Goodies - DrizzleORM
Drizzle ORM | %s
Angelelz
Angelelz14mo ago
Two options:
parentId: int('parent_id').default(sql`NULL`)
// or
parentId: int('parent_id').$default(null)
parentId: int('parent_id').default(sql`NULL`)
// or
parentId: int('parent_id').$default(null)
Thogn
ThognOP14mo ago
Thank you very much ,it got fixed now
Want results from more Discord servers?
Add your server