but I'm getting an error: `ERROR: There is a relat...
# orm-help
c
but I'm getting an error:
ERROR: There is a relation ambiguity during the migration. Please first name the old relation on your schema. The ambiguity is on a relation between Trip and User. Please name relations or change the schema in steps.
m
At first you probably just had one relation between User and Trip and then you added the second one and you got this error. I suggest the following: 1. Remove the new relation temporarily by commenting it. 2. Use the
@relation
to name the old relation. (So no need to adapt your example as you did so) 3. Run
prisma deploy
4. Bring back the new relation by uncommenting it. Run
prisma deploy
What happened under the hood is that your old relation already had a name. And with your self chosen names the server does not know what is the old and what is the new relation.
c
@marcus thanks for the feedback. I commented it out, and it deployed correctly, then tried uncommenting and got
You are creating a required relation, but there are already nodes that would violate that constraint.
Anyway I couldn’t figure out how to solve it so I created a new demo server and everything deployed correctly.
m
@captaindaylight: The new relation was probably this one
owner: User!
. So a
Trip
always needs to have a
User
in your schema. When you executed deploy, there were already nodes for the type
Trip
. If the deploy would be executed there would be Trips that do not have a user which would violate your schema.
You have 2 options to fix this: 1. What i often do:
prisma reset
This will wipe the database in your service. Therefore there can’t be invalid data. 2. First deploy that field as optional
owner: User
. Then execute a mutation
updateManyTrips
to connect existing trips to a dummy user. Afterwards you can make the field required and the server won’t complain.