Attempted to serialize scalar 'null' with incompatible type 'String' for field mainPhotoId.
See original GitHub issueBug description
Hello, when I’m trying to fetch an entity (Album) from following schema, the error occurs.
Attempted to serialize scalar 'null' with incompatible type 'String' for field mainPhotoId.
this.db.album.findUnique({ where: { id: albumId } });
// db is PrismaClient instance
How to reproduce
- Clone the repository https://github.com/zuffik/vivse-be
- run with
docker-compose up app-dev
- when server starts try to execute request from following postman export (use any image file for upload)
Playground.postman_collection.json.txt (change
.txt
to.json
, GH does not allow to upload json) - you should see this error
Expected behavior
It should return the album entity normally.
Prisma information
generator client {
provider = "prisma-client-js"
output = "../prisma/generated/client"
binaryTargets = ["native", "darwin", "debian-openssl-1.1.x", "linux-musl"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
email String @unique
name String?
password String
}
model Album {
id String @id @default(uuid())
createdAt DateTime @default(now())
label String
mainPhotoId String?
main Photo? @relation("MainPhoto", fields: [mainPhotoId], references: [id])
photos Photo[] @relation("Photos")
}
model ImageFile {
id String @id @default(uuid())
createdAt DateTime @default(now())
original String
small String
large String
editedFor Photo[] @relation("EditedFile")
originalFor Photo[] @relation("OriginalFile")
}
model Photo {
id String @id @default(uuid())
createdAt DateTime @default(now())
originalFileId String
editedFileId String?
albumId String
label String
album Album @relation("Photos", fields: [albumId], references: [id])
editedFile ImageFile? @relation("EditedFile", fields: [editedFileId], references: [id])
originalFile ImageFile @relation("OriginalFile", fields: [originalFileId], references: [id])
mainFor Album[] @relation("MainPhoto")
}
model Url {
token String @id
createdAt DateTime @default(now())
expiresAt DateTime
type UrlType
}
enum UrlType {
PICK
DOWNLOAD
}
Environment & setup
- OS: MacOS host with alpine docker image
- Database: postgres:14
- Node.js version: 16.13.2
Prisma Version
3.9.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Attempted to serialize scalar 'null' with incompatible type 'String'
Bug description I'm gettingAttempted to serialize scalar 'null' with incompatible type 'String' when trying to create new records that use ...
Read more >Compiler error with Prisma - typescript - Stack Overflow
I'm preparing a project with GraphQL server, using Prisma to connect with the database, all this with Typscript . And the compiler is...
Read more >prisma - bytemeta
Set foreign keys directly with a self relation field ... Attempted to serialize scalar 'null' with incompatible type 'String' for field mainPhotoId.
Read more >prisma - `findMany` with a `select` argument errors out with ...
(Note that the User field was automatically added by the VSCode ... findMany(Attempted to serialize scalar 'null' with incompatible type ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi. Sorry for not noticing the comments. In the meantime I updated the schema with another solution that was acceptable to my use case. I tried to test also the scheme attached to this issue but everything is working fine, so I suppose you can close the issue.
Hello here is the output:
When executing the query
the record is found: