M:N explicit join table from docs producing errors

(I posted on Discord, did some more troubleshooting and am still stuck, so posting here.)

The M:N explicit join table schema in the docs produces the following error for me:

  1. Error validating: The relation field products uses the scalar fields productId. At least one of those fields is required. Hence the relation field must be required as well.

  2. Error validating: The relation field tags uses the scalar fields tagId. At least one of those fields is required. Hence the relation field must be required as well.

As explained in the Redwood docs in the link above, the join table requires @id and @@unique fields, so looks different from the explicit M:N table in the Prisma docs.

Does anyone else get the above error when using the M:N schema in the above link? Any suggestions for what might be my issue here? Thank you.

edit: Looks like a recent issue that may have been fixed by Prisma? But still showing up for me. "Error validating: The relation field ... uses the scalar fields .... At least one of those fields is required. Hence the relation field must be required as well." is too restrictive when using composite keys · Issue #6042 · prisma/prisma · GitHub

Hiya Nick, I updated this doc a few weeks ago and was using it in my prototype project, but I haven’t started that project up in a few weeks (it’s a version or two behind the current Redwood release (0.29)).

It was working fine for me then (so could be related to your linked issue), when are you getting this error? I.e. during yarn rw dev or yarn rw prisma generate etc.

That table-schema not resembling what Prisma’s M-N example shows was deliberate, as I was factoring in Redwood’s CRUD requirements (I’m saying this cause I don’t know if anything has changed on Redwood’s end to not need it).

It also looks like that issue is tagged to Prisma 2.21, and their GitHub release has the current being 2.20, which Redwood’s API is also using.

Thanks! Yeah, someone from Prisma let me know those changes were fixed only 3 days ago and will most likely be released tomorrow.

He said to try prisma@dev instead to see if it works, so I’m currently creating a starter Prisma project to see if npx prisma@dev migrate dev works

Or if there’s a simpler way to use prisma@dev in my redwood project, maybe I should try that?

Not that I’m aware of, you just may have to update the args/config to match what Redwood uses. I’ve used other commands directly in a project by copying what Redwood/Yarn prints and adjusting the args to my needing, so it should work and is worth the effort I’d say!

Dependabot should catch the release from Prisma, I assume.

1 Like