jsonprismaprisma2

Prisma JSON upsert "must not be null"


I have the following schema:

myField              Json?                          @default("{}")

(notice the ?)

And when I try to insert a null value to that json field I get:

... must not be null. Please use undefined instead

I then tried to make it work with Prisma.JsonNull:

await prisma.website.upsert({
    update: {myField: data.myField || Prisma.JsonNull...},
    create:  {myField: data.myField || Prisma.JsonNull...},
  });

But then I got:

("[object Object]") cannot be serialized as JSON. Please only return JSON serializable data types.


Solution

  • Ok, so first I had to insert Prisma.JsonNull instead of a javascript null. Then I figured out that the problem stemmed from Nextjs that couldn't serialize the Prisma.JsonNull so I just did the following trick in my getStaticProps: JSON.parse(JSON.stringify(mydata with Prisma.JsonNull))