DT
Drizzle Teamβ€’14mo ago
titongo

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)
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}`
}
{
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,
},
}
//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.
4 Replies
titongo
titongoOPβ€’14mo ago
Bump please lil bump
Angelelz
Angelelzβ€’14mo ago
You need to summon @Andrew Sherman for this
titongo
titongoOPβ€’14mo ago
. πŸ•―πŸ•―οΈ πŸ•― πŸ•― πŸ•― πŸ•― πŸ•―@Andrew ShermanπŸ•― πŸ•― πŸ•― πŸ•― πŸ•― πŸ•―οΈπŸ•―οΈ Oops, it solved out of nowhere, apparently there was an error with the previous definition of created_at which was .defaultNow(), I just removed the default and now it is defined as
.default(sql`current_timestamp(3)`),
.default(sql`current_timestamp(3)`),
I tried going back to .defaultNow() and it works... I have no clue what happened from the planestcale console, this was my fix
titongo
titongoOPβ€’14mo ago
No description
Want results from more Discord servers?
Add your server