Skip to content

Error: ambiguous column name: value when running prisma studio (prisma v7, sqlite , better-auth ,nextjs) #1392

@HimanshuKumarDutt094

Description

@HimanshuKumarDutt094

Bug description

setup better auth 1.4.0 with prisma v7 and genrate schema
db push and all and open prisma studio
console throws error in studio
with "count" as (select cast(coalesce(count(*), 0) as text) as "value" from "public"."verification" where true) select "value", "identifier", "id", "updatedAt", "createdAt", "expiresAt", "count"."value" as "ps_count" from "public"."verification", "count" where true limit $1 offset 0
Error Details

column reference "value" is ambiguous
cli also throws
oaded Prisma config from prisma.config.ts.

Prisma Studio is running at: http://localhost:51212/

Error: ambiguous column name: value
at Object.execute (/home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/@prisma/studio-core-licensed/dist/data/node-sqlite/index.cjs:1:574)
at /home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/prisma/build/index.js:4754:1223
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async c (/home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/prisma/build/index.js:4713:11276)
at async /home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/prisma/build/index.js:4713:30864
at async c (/home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/prisma/build/index.js:4713:11276)
at async /home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/prisma/build/index.js:4713:21844
at async sor (/home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/prisma/build/index.js:4713:6089)
at async Server. (/home/himanshu77/projects/ct3a-tests/prismas/sqlite_test/node_modules/prisma/build/index.js:4713:7554) {
code: 'ERR_SQLITE_ERROR',
errcode: 1,
errstr: 'SQL logic error'
}

Severity

🚨 Critical: Data loss, app crash, security issue

Reproduction

https://github.com/HimanshuKumarDutt094/prismav7-bug-report.git

Expected vs. Actual Behavior

db studio should just run (dev server generate db push works)

Frequency

Consistently reproducible

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

yes v6 was working

Workaround

downgrade to v6 prisma-client-js

Prisma Schema & Queries

// Prisma schema for Better Auth
// learn more: https://better-auth.com/docs/concepts/database

generator client {
provider = "prisma-client"
output = "../generated/prisma"
}

// NOTE: When using mysql or sqlserver, uncomment the //@db.Text annotations in model Account below
// Further reading:
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string

datasource db {
provider = "sqlite"
}

model Post {
id String @id @default(cuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedat

createdBy User @relation(fields: [createdById], references: [id])
createdById String

@@index([name])
}

model User {
id String @id
name String //@db.Text
email String
emailVerified Boolean @default(false)
image String? //@db.Text
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedat
sessions Session[]
accounts Account[]
posts Post[]

@@unique([email])
@@Map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime @default(now())
updatedAt DateTime @updatedat
ipAddress String? //@db.Text
userAgent String? //@db.Text
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([token])
@@Map("session")
}

model Account {
id String @id
accountId String //@db.Text
providerId String //@db.Text
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String? //@db.Text
refreshToken String? //@db.Text
idToken String? //@db.Text
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String? //@db.Text
password String? //@db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedat

@@Map("account")
}

model Verification {
id String @id
identifier String //@db.Text
value String //@db.Text
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedat

@@Map("verification")
}

Prisma Config

// Add your `prisma.config.ts`
import { defineConfig } from "prisma/config";

import { env } from "./src/env";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env.DATABASE_URL,
  },
});

Logs & Debug Info

// Debug logs here

Environment & Setup

  • OS: Linux Mint 22.2
  • **Database:**Sqlite
  • Node.js version: 22.19

Prisma Version

prisma               : 7.0.0
@prisma/client       : 7.0.0
Operating System     : linux
Architecture         : x64
Node.js              : v22.19.0
TypeScript           : 5.9.3
Query Compiler       : enabled
PSL                  : @prisma/prisma-schema-wasm 6.20.0-16.next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513
Schema Engine        : schema-engine-cli 0c19ccc313cf9911a90d99d2ac2eb0280c76c513 (at node_modules/@prisma/engines/schema-engine-debian-openssl-3.0.x)
Default Engines Hash : 0c19ccc313cf9911a90d99d2ac2eb0280c76c513
Studio               : 0.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions