Questions tagged [prisma2]

For questions about Version 2 of the Prisma ORM

232 questions
21
votes
13 answers

"Property does not exist" when I want to use model added in Prisma.schema

I'm working on ReactJS project with NextJS Framework and Prisma to manage connection and queries to the DB. On my local project the Support model is found and when I use it in my API and build my project it's ok. But when I push my project on…
Peter
  • 263
  • 1
  • 3
  • 7
19
votes
2 answers

how to upsert many fields in prisma ORM

How can I upsert many fields in prisma ORM with one query? I don't want to use upsert fields one by one. Can I upsert all of them with one query?
xander
  • 201
  • 1
  • 2
  • 8
17
votes
8 answers

Prisma Schema not updating properly after adding new fields

As the title states, I am using Prisma 2 in a Next JS app. I have a very simple schema: model User { id Int @id @default(autoincrement()) firstName String middleName String? firstLastname String secondLastname…
Isaac
  • 171
  • 1
  • 1
  • 7
15
votes
5 answers

Prisma many-to-many relations: create and connect

In my Prisma schema, I have a many-to-many relationship between posts and categories. I've added @map options to match the Postgres snake_case naming convention: model Post { id Int @id @default(autoincrement()) title …
Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
14
votes
1 answer

Can't make two 1:1 relations in one model in Prisma. Ambiguous relation detected

I'm trying to make two 1:1 relations in one model in Prisma ORM, but got following error: Error validating model "Person": Ambiguous relation detected. The fields placeOfBirth and placeOfDeath in model Person both refer to Place. Please provide…
11
votes
2 answers

LEFT JOINS and aggregation in a single Prisma query

I have a database with multiple tables that frequently need to be queried with LEFT JOIN so that results contain aggregated data from other tables. Snippet from my Prisma schema: model posts { id Int @id @unique…
James
  • 325
  • 1
  • 3
  • 15
11
votes
1 answer

Prisma - How to define compound unique constraint with fields in multiple models?

I have this not so straightforward model relationship in Prisma. User --< Enrollment >-- Course and I can't figure out how to ensure the Course title field is unique just among that user's created courses. In other words, I dont want one user to…
TemuujinNat
  • 135
  • 1
  • 1
  • 7
11
votes
5 answers

prisma findUnique where takes only one unique argument

I ran into an issue where I need to check if a user exists by his username and email since both are unique fields in the database, but I got an error. Argument where of type UserWhereUniqueInput needs exactly one argument, but you provided username…
ahmdtalat
  • 149
  • 1
  • 1
  • 7
11
votes
2 answers

Prisma client query for latest

Given the following schema. How would I query for the latest commit on each repository using the prisma2 client? model Commit { id String @default(uuid()) @id date DateTime @default(now()) } model Branch { id String …
TheAschr
  • 899
  • 2
  • 6
  • 19
9
votes
3 answers

prisma Order by relation has only _count property. Can not order by relation fields

consider following Prisma schema: model Conversation { id Int @id @default(autoincrement()) createdAt DateTime @db.Timestamp(6) messages ConversationMessage[] } model…
E.Belekov
  • 467
  • 1
  • 7
  • 14
9
votes
0 answers

Share Prisma types with frontend application?

I've been looking at Prisma (Nodejs ORM) and have been wondering how to share the autogenerated TypeScript types with a front-end application. As far as I can tell, the Prisma client auto-generates all DTOs but offers no simple way to export or…
Xen_mar
  • 8,330
  • 11
  • 51
  • 74
9
votes
3 answers

How to run `prisma generate` in production?

I'm confused about how Prisma code generation in production works. The Prisma CLI is supposed to be installed in devDependencies, yet the npx prisma generate command needs to be available in production, since the generated code is necessary for the…
Robert Moore
  • 2,207
  • 4
  • 22
  • 41
8
votes
1 answer

Prisma 2: Setting Minimum & Maximum Length of a String type

I am creating a model using Prisma 2 and want to set a minimum and maximum length for one of the fields. I.e., something like this: model Post { ... title String @min(3) @max(240) ... } I just made up the above syntax. I am wondering if…
Moshe
  • 6,011
  • 16
  • 60
  • 112
8
votes
3 answers

Make a change to the database with Prisma.js without having to reset the whole thing

How can make a change to the database with Prisma.js without having to reset the whole thing? if I have used this command npx prisma migrate dev --name role-makeOptional-NormalizedName I will lose all of the data in my database but I don't lose my…
x19
  • 8,277
  • 15
  • 68
  • 126
7
votes
3 answers

How to solve Apollo Studio Sanbox Cors?

I can't use apollo Studio. After migration for Graphql playground. When I try to run in localhost and redirect me to apollo studio sanbox https://studio.apollographql.com/sandbox?endpoint=http%3A%2F%2Flocalhost%3A5018%2Fgraphql: Unable to connect to…
lohnsonok
  • 471
  • 6
  • 12
1
2 3
15 16