Can't run drizzle db:push due to error yet the code hasn't changed

So i am trying to push my new schema to planetScale however i run into this error:
Error: target: meally.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'createdAt' (errno 1067) (sqlstate 42000) (CallerID: 9d6l772g9pp919ug46mn): Sql: "alter table recipes modify column isPublic boolean not null", BindVars: {REDACTED}
at PromiseConnection.query (G:\GitHub\Meally\node_modules\.pnpm\d[email protected]\node_modules\drizzle-kit\index.cjs:35317:26)
at Command.<anonymous> (G:\GitHub\Meally\node_modules\.pnpm\d[email protected]\node_modules\drizzle-kit\index.cjs:52802:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_INVALID_DEFAULT',
errno: 1067,
sql: 'ALTER TABLE `recipes` MODIFY COLUMN `isPublic` boolean NOT NULL;',
sqlState: '42000',
sqlMessage: `target: meally.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'createdAt' (errno 1067) (sqlstate 42000) (CallerID: 9d6l772g9pp919ug46mn): Sql: "alter table recipes modify column isPublic boolean not null", BindVars: {REDACTED}`
}
Error: target: meally.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'createdAt' (errno 1067) (sqlstate 42000) (CallerID: 9d6l772g9pp919ug46mn): Sql: "alter table recipes modify column isPublic boolean not null", BindVars: {REDACTED}
at PromiseConnection.query (G:\GitHub\Meally\node_modules\.pnpm\d[email protected]\node_modules\drizzle-kit\index.cjs:35317:26)
at Command.<anonymous> (G:\GitHub\Meally\node_modules\.pnpm\d[email protected]\node_modules\drizzle-kit\index.cjs:52802:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_INVALID_DEFAULT',
errno: 1067,
sql: 'ALTER TABLE `recipes` MODIFY COLUMN `isPublic` boolean NOT NULL;',
sqlState: '42000',
sqlMessage: `target: meally.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'createdAt' (errno 1067) (sqlstate 42000) (CallerID: 9d6l772g9pp919ug46mn): Sql: "alter table recipes modify column isPublic boolean not null", BindVars: {REDACTED}`
}
When i ran this db:push earlier this week i didn't have any issues and i din't change anything so i don't know whats up there find my schema attached
12 Replies
barry
barry17mo ago
why the notnull if there is default
Jacob
JacobOP17mo ago
that's a great question i don't really know why i did that, even once removing that is still won't work so that's not really my issue. but thank you for picking that up
barry
barry17mo ago
what if you do default(0)
Jacob
JacobOP17mo ago
Nah that doesn't work
barry
barry17mo ago
Also, now is not a date I think? so doing mode date But defaultNow get rid of mode date maybe
Jacob
JacobOP17mo ago
if you have a look at ths schmea attached you can see my date fields
createByName: varchar('lastUpdatedBy', { length: 191 }).notNull(),
createdAt: timestamp('createdAt', { mode: 'date' }).defaultNow(),
lastUpdated: timestamp('lastUpdated', { mode: 'date' })
.defaultNow()
.onUpdateNow(),
lastUpdatedBy: varchar('lastUpdatedBy', { length: 191 }).notNull(),
lastUpdatedByName: varchar('lastUpdatedBy', { length: 191 }).notNull(),
createdBy: varchar('createdBy', { length: 191 }).notNull(),
createByName: varchar('lastUpdatedBy', { length: 191 }).notNull(),
createdAt: timestamp('createdAt', { mode: 'date' }).defaultNow(),
lastUpdated: timestamp('lastUpdated', { mode: 'date' })
.defaultNow()
.onUpdateNow(),
lastUpdatedBy: varchar('lastUpdatedBy', { length: 191 }).notNull(),
lastUpdatedByName: varchar('lastUpdatedBy', { length: 191 }).notNull(),
createdBy: varchar('createdBy', { length: 191 }).notNull(),
barry
barry17mo ago
get rid of date
Jacob
JacobOP17mo ago
yeh that still doesn't work
barry
barry17mo ago
timestamp("").defaultNow() doesnt work?
Jacob
JacobOP17mo ago
Correct, ussaly it does but for some reason it still error with all of that, it's weird becuase all this code was working no that long ago beacuse i only reason for the changes is for my users schema and stuff but that isn't whjere the issue lyes which is weird
barry
barry17mo ago
take it to drizzles discord then, seems like a weird bug, and if they do help please say more than "doesnt work" https://discord.gg/gDVHNhbN
.default(sql`(CURRENT_TIMESTAMP(3))`)
.default(sql`(CURRENT_TIMESTAMP(3))`)
Want results from more Discord servers?
Add your server