Prisma keeps pasting incorrect schema
I'm admittedly not great with backend stuff, so I don't know if my Tournament table schema is bad, but after editing that table I keep having this weird issue where this clearly incorrect data keeps getting pasted into my User table on save. I've tested this on both VSCode and WebStorm, same thing happens.
prisma
and @prisma/client
are on ^5.18.0
schema.prisma
Solution:Jump to solution
```tsx
model User {
id String @id @default(cuid())
tournamentsHosted Tournament[] @relation(name: "TournamentHost")
tournamentsJoined Tournament[]...
12 Replies
So that’s expected (and correct!) behavior.
https://www.prisma.io/docs/orm/prisma-schema/data-model/relations
The thing to note there is this quote:
At a Prisma ORM level, a connection between two models is always represented by a relation field on each side of the relation.
Relations (Reference) | Prisma Documentation
A relation is a connection between two models in the Prisma schema. This page explains how you can define one-to-one, one-to-many and many-to-many relations in Prisma.
The thing putting in those lines is our Prisma formatter, which is seeing the missing “back relation” fields and adding them
ok i see, in that case should i ignore the linter complaining about the two Tournament fields? because every time i try to remove one of them it adds more fields automatically 😅
You can change the names to something better. Maybe in your case it would be tournamentsHosted and tournamentsAttended?
is this what you were talking about? whenever i try to change them, it adds the fields right back, and then if i delete the fields it added, it adds user fields to the tournament model
im sorry i dont know if im doing something wrong im just so confused 😭
Huh yeah that does look wrong. What version of the VSCode extension are you on?
5.18.0
weird. Let me try and replicate this.
Okay, figured it out 🙂
So you have two relations.
One is "one-to-many" which is User<->Tournament (one user can host many tournaments)
The other is "many-to-many" which is (also) User<->Tournament (one user can join many tournaments, each tournament has many users.
Let's break down the two relations:
So that will be both directions of the first "one-to-many" relation.
Now to add a many-to-many, we just have to add lists of models on both sides.
Now if you do that, you'll see an error under "tournamentsHosted" about an ambiguous relation. Then you just have to add a name to the host<->tournamentsHosted relation (like you had)
Solution
There you go!
it worked! thank you so much for your help, its greatly appreciated
no prob