Default values not working for insert
await db
.insert(Drizzle.User)
.values({
email,
password: Utils.getHash(password)
})
.returning();await db
.insert(Drizzle.User)
.values({
email,
password: Utils.getHash(password)
})
.returning();export const User = pgTable(
'User',
{
email: text('email').notNull(),
id: text('id').default(crypto.randomUUID()).primaryKey().notNull(),
joinedDate: timestamp('joinedDate', { mode: 'string', precision: 3 }).defaultNow().notNull(),
lastLoginDate: timestamp('lastLoginDate', { mode: 'string', precision: 3 }).defaultNow().notNull(),
logins: integer('logins').default(1).notNull(),
password: text('password').notNull()
},
(table) => ({
email_key: uniqueIndex('User_email_key').on(table.email)
})
);export const User = pgTable(
'User',
{
email: text('email').notNull(),
id: text('id').default(crypto.randomUUID()).primaryKey().notNull(),
joinedDate: timestamp('joinedDate', { mode: 'string', precision: 3 }).defaultNow().notNull(),
lastLoginDate: timestamp('lastLoginDate', { mode: 'string', precision: 3 }).defaultNow().notNull(),
logins: integer('logins').default(1).notNull(),
password: text('password').notNull()
},
(table) => ({
email_key: uniqueIndex('User_email_key').on(table.email)
})
);Aug 12, 10:07:45PM error: PostgresError: null value in column "id" of relation "User" violates not-null constraint
at ErrorResponse (webpack-internal:///(api)/../../../node_modules/.pnpm/postgres@3.3.5/node_modules/postgres/src/connection.js:785:66)
at handle (webpack-internal:///(api)/../../../node_modules/.pnpm/postgres@3.3.5/node_modules/postgres/src/connection.js:487:6)
at Socket.data (webpack-internal:///(api)/../../../node_modules/.pnpm/postgres@3.3.5/node_modules/postgres/src/connection.js:328:9)
at Socket.emit (node:events:513:28)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)Aug 12, 10:07:45PM error: PostgresError: null value in column "id" of relation "User" violates not-null constraint
at ErrorResponse (webpack-internal:///(api)/../../../node_modules/.pnpm/postgres@3.3.5/node_modules/postgres/src/connection.js:785:66)
at handle (webpack-internal:///(api)/../../../node_modules/.pnpm/postgres@3.3.5/node_modules/postgres/src/connection.js:487:6)
at Socket.data (webpack-internal:///(api)/../../../node_modules/.pnpm/postgres@3.3.5/node_modules/postgres/src/connection.js:328:9)
at Socket.emit (node:events:513:28)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)what is going on here? shouldn't the value be filled in by default?