DT
Join ServerDrizzle Team
help
Invalid default value for timestamp
Hi, I have recently started learning SQL and I've run into this problem with Drizzle Kit. I have this promoCodes table:
// PlanetScale (MySQL) + Drizzle ORM
export const promoCodes = mysqlTable(
'promo_codes',
{
id: serial('id').primaryKey().autoincrement(),
createdAt: timestamp('created_at').defaultNow(),
updatedAt: timestamp('updated_at').onUpdateNow(),
// ...
}
)
and when I try to push it using pnpm drizzle-kit push:mysql
, I get this error: target: xxx.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'updated_at' (errno 1067) (sqlstate 42000) (CallerID: ues4twwhaqs5wh3lm76u): Sql: "alter table promo_codes modify column created_at timestamp default now()", BindVars: {REDACTED}
@Andrii Sherman
If you are using PlanetScale try to change .defaultNow() to
.default(sql`CURRENT_TIMESTAMP`)
PlanetScale is restricting (now()) expressions
2 Messages Not Public
Sign In & Join Server To View
Could you try running the alter column query manually on planetscale to check if it works at all?
Message Not Public
Sign In & Join Server To View
Hey is this error still showing up or have you found a workaround?
2 Messages Not Public
Sign In & Join Server To View
I had to change it to
and for updateNow()
.default(sql`CURRENT_TIMESTAMP(3)`)
and for updateNow()
.default(sql`CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)`)
but that updateNow is probably really not recommended
For some reason planetsale requires
CURRENT_TIMESTAMP
to be called as a function and not just an interpreted valueWeird
We'll probably need to allow customizing the
We'll probably need to allow customizing the
onUpdate
value, in addition to onUpdateNow