Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tangtai opened this issue May 30, 2024 · 4 comments · Fixed by #1909, #1907 or #1921
Closed

Comments

@tangtai
Copy link

tangtai commented May 30, 2024

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/[email protected]/node_modules/postgres/src/connection.js:803:66)\n' +
' at handle (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:489:6)\n' +
' at Socket.data (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/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()
 }
@tangtai
Copy link
Author

tangtai commented May 31, 2024

current solution i can think of is to assign a default value to user id

export const users = createTable("user", {
  id: varchar("id", { length: 255 })
    .notNull()
    .primaryKey()
    .$defaultFn(() => sql`gen_random_uuid()`)
}

@yowayb
Copy link

yowayb commented Jun 2, 2024

and for SQLite .$defaultFn(() => crypto.randomUUID())

@vladavoX
Copy link

vladavoX commented Jun 2, 2024

same error with same initial setup

@TheDevilOnLine
Copy link
Contributor

Same applies to MySQL as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment