I can't figure out why... And I have another model...
# orm-help
c
I can't figure out why... And I have another model using the exact same column type and it works without any issue Did I missed something ?
1
r
Hi @Clément Guibout 👋 Can you please share the complete schema and the query?
c
Hello Raphael
Sorry for the late response Here is the whole schema:
Copy code
model Event {
  evt_id           String        @id @default(uuid())
  evt_title        String
}

model Organization {
  org_id             String             @id @default(uuid())
  org_name           String
}
And here is the request that fails
Copy code
const newEvent = await prisma.event.create({
                data: {
                    evt_title: parsedCreateEventSchema.evt_title
                },
            })
as you can see, I am just requesting to create an object, so the id should be calculated without any issue. I have a similar request for the Organizations model that just works fine, this is strange... I have seen other people having the same issue online, but no fix sadly 😞 @Raphael Etim
Also, this is the error I get:
Copy code
61 try {
→  62     const newEvent = await prisma.event.create(
  Unique constraint failed on the fields: (`evt_id`)
r
Hi @Clément Guibout, I'm taking a look.
Did you add random records with an id or did you import records and manually set the id on each row?
This is a github discussion link that addresses this similar issue
c
I used prisma.event.create to create a first event (which works fine), but the second does not work
Actually, I added a relation between the events and the organizations The link from event is
Copy code
evt_organizer    Organization  @relation(fields: [evt_id], references: [org_id])
and from the organizer its
Copy code
org_events         Event[]
I guess the evt_id is the same as the org_id (which is an uuid) So the first can be created, but since the org can have many events, I can't create another one (it will have the org_id as evt_id, but it is already in use by the first event)
I need to figure out a way to change this
In fact I need my evt_id to be a proper uuid, not the same as the org's one
r
Hi @Clément Guibout, did you figure this out?
c
Yes, I did!
The thing was that my relation was wrong
r
I'm glad you were able to figure this out. Do let us know if you have any other queries.
1
c
Hello Raphael I do have another query that is currently driving me crazy 😢 https://prisma.slack.com/archives/CA491RJH0/p1662676935992939 Let me know if you have any time to take a look at it Thanks in advance
r
Hi @Clément Guibout, I've responded in that message thread.