© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
14 replies
jakeleventhal

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?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Nested insert not working
Drizzle TeamDTDrizzle Team / help
2y ago
Placeholders in inserting: db.insert().values(placeholder('example'))
Drizzle TeamDTDrizzle Team / help
3y ago
Subquery in insert().values()
Drizzle TeamDTDrizzle Team / help
2y ago
Using default values removes columns from insert and update types
Drizzle TeamDTDrizzle Team / help
2y ago