studio
studio copied to clipboard
PrismaStudio Obscures Error with Database Having First Row/Record as Duplicate of Column/Field Names
Bug description
When I ran node prisma.js
, I received the following error:
PrismaClientKnownRequestError:
Invalid `prisma.patient.findMany()` invocation in
/Users/emidac/Documents/code/aura/aura-patients-app/prisma.js:7:44
4
5 async function main() {
6 // ... you will write your Prisma Client queries here
→ 7 const allPatients = await prisma.patient.findMany(
Inconsistent column data: Could not convert value "age" of the field `age` to type `Int`.
at In.handleRequestError (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:122:6854)
at In.handleAndLogRequestError (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:122:6188)
at In.request (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:122:5896)
at async l (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:127:10871)
at async main (/Users/emidac/Documents/code/aura/aura-patients-app/prisma.js:7:23) {
code: 'P2023',
clientVersion: '5.11.0',
meta: {
modelName: 'Patient',
message: 'Could not convert value "age" of the field `age` to type `Int`.'
}
}
Initially, I thought that the PrismaClient was mistakenly treating my Column/Field Names as a row/record of values.
Instead, it turns out that my Database did, in fact, have a first row/record populated with TEXT/String values replicating the Column/Field Names rather than valid values such as an INTEGER/Int value for the "age" field.
However, before I went to double-check in DB Browser for SQLite, what I saw in Prisma Studio actually confused me further as it didn't show this first problematic row:
How to reproduce
- Create a db with the first row/record incorrectly containing Column/Field Names in which the correct value type of one of the fields is supposed to be an INTEGER/Int
- View the db in Prisma Studio
- See no evidence of the problematic row/record
Expected behavior
I expect Prisma Studio to show me the problematic row/record rather than obscure it
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model Patient {
name String @id @unique
firstName String @map("first_name")
age Int
height Int
weight Int
gender String
medications String
bodyTemperatures String @map("body_temperatures")
@@map("patient")
}
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
async function main() {
// ... you will write your Prisma Client queries here
const allPatients = await prisma.patient.findMany()
console.log(allPatients.map((patient) => patient.name))
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
Environment & setup
- OS: macOS Sonoma 14.4
- Architecture: arm64
- Database: SQLite
- Node.js version: 20.11.1
Prisma Version
5.11.0
Interesting, Prisma Studio should jsut run a findMany()
for that table under the hood and usually fails the exact same way as your script did. I don't really understand how and why id skipped that first entry, although by default Studio using pagination (600 first entries in your screenshot) - and maybe somehow added some sorting as well? Can you reproduce this consistently?