Record to update not found | NextJs + Prisma

I use the following URL to verify a record:

https://foo.bar.com/letter/verify/cln8sixq1001na9uue0pn3i4n

but sometimes Prisma don’t find the record to update.

My getServerSidePropscode looks like this:

export const getServerSideProps = async (ctx) => {
  console.log("ctx: ", ctx);
  const { verifyId } = ctx.params;

  try {
    const letter = await prisma.letter.update({
      where: {
        verifyId: verifyId,
      },
      data: {
        verified: true,
        verifyId: null,
      },
    });

    return { props: { letter } };
  } catch (error) {
    console.log("verifyError: ", error);
    return {
      redirect: {
        destination: "/letter/verifyError",
        permanent: false,
      },
    };
  }
};

Could be the problem that I update the same property (verifyId) which I use to find the record?

Error Log:

0|tcs      | verifyError:  PrismaClientKnownRequestError:
0|tcs      | Invalid `prisma.letter.update()` invocation:
0|tcs      |
0|tcs      |
0|tcs      | An operation failed because it depends on one or more records that were required but not found. Record to update not found.
0|tcs      |     at zr.handleRequestError (/root/tcs/node_modules/@prisma/client/runtime/library.js:122:8308)
0|tcs      |     at zr.handleAndLogRequestError (/root/tcs/node_modules/@prisma/client/runtime/library.js:122:7697)
0|tcs      |     at zr.request (/root/tcs/node_modules/@prisma/client/runtime/library.js:122:7307)
0|tcs      |     at async /root/tcs/.next/server/pages/letter/verify/[verifyId].js:256:24 {
0|tcs      |   code: 'P2025',
0|tcs      |   clientVersion: '5.0.0',
0|tcs      |   meta: { cause: 'Record to update not found.' }
0|tcs      | }

  • have you try to run prisma generate to generate the client before running the server ?

    – 

  • can you explain this a little bit?

    – 

Leave a Comment