rpc error: code = InvalidArgument desc = Invalid default value

When I do drizzle-kit push:mysql I get the following error:
Error: target: (dbname).-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'created_at' (errno 1067) (sqlstate 42000) (CallerID: 12s8gn7khn0atcm380g0): Sql: "alter table posts modify column id varchar(36) not null", BindVars: {REDACTED}
    at PromiseConnection.query (C:\Users\...)
    at Command.<anonymous> (C:\Users\...)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) 

{
  code: 'ER_INVALID_DEFAULT',
  errno: 1067,
  sql: 'ALTER TABLE `posts` MODIFY COLUMN `id` varchar(36) NOT NULL;',
  sqlState: '42000',
  sqlMessage: `target: (dbname).-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'created_at' (errno 1067) (sqlstate 42000) (CallerID: 12s8gn7khn0atcm380g0): Sql: "alter table posts modify column id varchar(36) not null", BindVars: {REDACTED}`
}


relevant code:
//app/services/schemas/schema.ts
const v4ID = (name: string) =>
  varchar(name, { length: 36 }).$defaultFn(() => crypto.randomUUID());

export const users = mysqlTable("users", {
  id: v4ID("id").primaryKey(),
  createdAt: timestamp("created_at", { fsp: 3, mode: "string" }).default(
    sql`current_timestamp(3)`
  ),
//drizzle.config.ts
export default {
  schema: "./app/services/schemas/*",
  out: "./drizzle",
  driver: "mysql2",
  dbCredentials: {
  // the dbURL is from planetscale
    connectionString: config.dbURL,
  },
}


I don't understand the problem at all, the error seems to indicated it has to do with the id but the error message talks about created_at.
Was this page helpful?