P
Prisma•2mo ago
FrancyMak

Prisma Studio Error

Hello guys, asking here because it's a bit urgent. I'm trying to connect
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
userId String @unique

freelancer Freelancer?
settings Settings?
reviews Review[]
tickets Ticket[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model Freelancer {
id Int @id @default(autoincrement())
userId String @unique
user User @relation(fields: [userId], references: [userId], onDelete: Cascade, onUpdate: Cascade)

avgRating Float @default(0)
departments FreelancerDepartments[]
commissions Commission[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
userId String @unique

freelancer Freelancer?
settings Settings?
reviews Review[]
tickets Ticket[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model Freelancer {
id Int @id @default(autoincrement())
userId String @unique
user User @relation(fields: [userId], references: [userId], onDelete: Cascade, onUpdate: Cascade)

avgRating Float @default(0)
departments FreelancerDepartments[]
commissions Commission[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
With prisma studio, but i'm getting Argument connect of type UserWhereUniqueInput needs at least one of id or userId arguments. Available options are marked with ?.
19 Replies
Prisma AI Help
Prisma AI Help•2mo ago
Skipping coffee for instant knowledge! Let's brew that AI answer now. Based on the information provided in your question and the knowledge sources available, I can offer some insights into the error you're encountering with Prisma Studio. The error message you're seeing suggests that when trying to create or connect a Freelancer to a User in Prisma Studio, you're not providing the required unique identifier for the User model. According to your schema, the User model has two potential unique identifiers: 1. id: An auto-incrementing integer 2. userId: A unique string When creating a Freelancer and trying to connect it to a User in Prisma Studio, you need to provide either the id or the userId of the User you want to connect to. This error is similar to issues described in Github Issue: Unexpected non-type-safety in findUnique and Github Issue: Runtime error that occurs in findUnique() when unique constraint is composed of one field, where Prisma expects at least one unique identifier to be provided in operations involving relations. To resolve this issue in Prisma Studio: 1. When creating a new Freelancer, make sure to fill in the userId field with the userId of an existing User. 2. Alternatively, you could use the id of an existing User if you prefer. If you're still encountering issues after ensuring you've provided a valid unique identifier, you might want to try the following: 1. Regenerate your Prisma Client to ensure it's up to date with your schema:
npx prisma generate

npx prisma generate

2. Verify that your database schema matches your Prisma schema by running:
npx prisma db pull

npx prisma db pull

If the problem persists after these steps, it might be worth checking if there are any inconsistencies between your Prisma schema and the actual database schema. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
RaphaelEtim
RaphaelEtim•2mo ago
Hi @FrancyMak Within the Prisma Studio interface, are you entering a value for userId in Freelancer tabe that has a corresponding id in User table
FrancyMak
FrancyMakOP•2mo ago
Hello! So I did this: - Created a user record in the User model which worked fine - Saved the changes - Switched to the freelancer model and I tried to create the freelancer profile by adding a record and entering the same user id that I used in the user schema But when I try to save the values I get that error It’s kinda weird, because if I set the relation as int id it works fine So instead of [userId] I set [id] on both I’m using prisma Postgres, just to add more info
RaphaelEtim
RaphaelEtim•2mo ago
Instead of entering the userId, can you click on the User relation and check the id field as shown in the image
No description
FrancyMak
FrancyMakOP•2mo ago
It just shows the empty freelancer model
FrancyMak
FrancyMakOP•2mo ago
No description
RaphaelEtim
RaphaelEtim•2mo ago
Can you open the freelancer table in a new tab? Once its open you see the same interface as the image i shared
FrancyMak
FrancyMakOP•2mo ago
Sure Sorry but I can’t create a record in that tab Like you did Freelancer table is empty, if I try to connect the user to the freelancer table I get the error Looks like you have a record in your example I just switched to a local Postgres instance and I get the same issue
FrancyMak
FrancyMakOP•2mo ago
The error modal is also bugged btw
No description
FrancyMak
FrancyMakOP•2mo ago
No description
FrancyMak
FrancyMakOP•2mo ago
Mhh i have these entries now looks like the relation is not completed but a record is sort of created? idk
FrancyMak
FrancyMakOP•2mo ago
No description
FrancyMak
FrancyMakOP•2mo ago
If I click on open in a new tab, it does nothing [ { "modelName": "Freelancer", "operation": "create", "args": { "data": { "user": { "connect": {} }, "avgRating": 0, "departments": {}, "commissions": {}, "updatedAt": "2025-01-31T18:22:38.740Z" }, "select": { "id": true, "userId": true, "user": true, "avgRating": true, "departments": true, "commissions": true, "createdAt": true, "updatedAt": true } } } ] When i save the changes, i get this query Maybe
"user": {
"connect": {}
},
"user": {
"connect": {}
},
RaphaelEtim
RaphaelEtim•2mo ago
i'm trying to share a recording of how i performed the operation in Prisma Studio
FrancyMak
FrancyMakOP•2mo ago
Ok
FrancyMak
FrancyMakOP•2mo ago
Ok i did the same thing And i have a relation now
FrancyMak
FrancyMakOP•2mo ago
No description
FrancyMak
FrancyMakOP•2mo ago
So i can't connect the two records by entering the userId of the relation in prisma studio

Did you find this page helpful?