Skip to content

bug: create-T3 app with drizzle missing default id value for users table on new user #1906

@tangtai

Description

@tangtai

Provide environment information

System:
OS: macOS 14.2.1
CPU: (12) arm64 Apple M2 Max
Memory: 1.44 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
pnpm: 9.0.6 - ~/.nvm/versions/node/v18.17.0/bin/pnpm
Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman

Describe the bug

[next-auth][error][adapter_error_createUser]
https://next-auth.js.org/errors#adapter_error_createuser null value in column "id" of relation "t3-c_user" violates not-null constraint {
message: 'null value in column "id" of relation "t3-c_user" violates not-null constraint',
stack: 'PostgresError: null value in column "id" of relation "t3-c_user" violates not-null constraint\n' +
' at ErrorResponse (webpack-internal:///(rsc)/./node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/connection.js:803:66)\n' +
' at handle (webpack-internal:///(rsc)/./node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/connection.js:489:6)\n' +
' at Socket.data (webpack-internal:///(rsc)/./node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/connection.js:330:9)\n' +
' at Socket.emit (node:events:514:28)\n' +
' at addChunk (node:internal/streams/readable:324:12)\n' +
' at readableAddChunk (node:internal/streams/readable:297:9)\n' +
' at Readable.push (node:internal/streams/readable:234:10)\n' +
' at TCP.onStreamRead (node:internal/stream_base_commons:190:23)\n' +
' at TCP.callbackTrampoline (node:internal/async_hooks:130:17)',
name: 'PostgresError'
}
GET /api/auth/callback/discord?code=KlGcFSWb4LrXqN4kDv8zdQcIj8UYzX&state=aU_NrRWwP9zBsz6FJ13Pt5hzyWLZq86t7HSwV5qQh1k 302 in 516ms
GET /api/auth/error?error=OAuthCreateAccount 302 in 14ms
GET /api/auth/signin?error=OAuthCreateAccount 200 in 5ms

Reproduction repo

no applicable

To reproduce

pnpm create t3-app@latest --CI --trpc --tailwind --nextAuth --drizzle --dbProvider postgress

pnpm db:push

pnpm dev

set up discord_app

login with discord provider

Additional information

the issue occur when logging with a new user with oAuth by discord, no user_id is created by drizzle ORM.

where as Prisma supports CUID

model User {
    id            String    @id @default(cuid())
}

as Drizzle requires not-null value without creating one on account creation

export const users = createTable("user", {
  id: varchar("id", { length: 255 }).notNull().primaryKey()
 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions