For questions about Version 2 of the Prisma ORM
Questions tagged [prisma2]
232 questions
7
votes
2 answers
Prisma: Query across multiple schemas in a database
Does prisma support the ability to fetch data from multiple schemas from within a single database?

Muhammad Rehan Qadri
- 6,824
- 1
- 17
- 18
6
votes
1 answer
I want to use Prisma to store nested comments (like on reddit). How can I retrieve all the nested comments?
I want to model nested comments, like on reddit. I'm using a one-to-many self relation like this:
model Comment {
[...]
parentId String?
parent Comment? @relation("ParentChildren", fields: [parentId], references: [id])
children Comment[]…

lumenwrites
- 1,287
- 4
- 18
- 35
6
votes
3 answers
Too many Prisma migration files
I'm currently working on a project that we are using Prisma 2 and postgreSQL as database support. From my understanding, whenever I made changes to the schema.prisma file and I want to migrate the changes to the database, I run prisma migrate dev…

Snowpanther
- 115
- 1
- 6
6
votes
4 answers
Logging with Prisma 2 and NestJS - Dependency Injection problem?
Currently on my first NestJS project. I am using Prisma 2, and would like to log the queries to the console in debug mode, to learn and inspect and avoid n+1 etc!
I have created the prisma.service.ts:
import { Injectable, OnModuleInit,…

turbzcoding
- 173
- 1
- 6
6
votes
2 answers
prisma2 set length and column type in prisma schema
how can i set string(varchar) length for string type be 50 and define a column be TEXT in prisma schema, for user table i want name be varchar(50) and bio be Text column.
im creating my tables by prisma migrate save and up.
model User {
id …

devmrh
- 1,171
- 4
- 19
- 46
5
votes
0 answers
Prisma: How to get position of a record after sort in prisma?
I have a waitlist where users signup with their email. Then they can use their invite code and invite more users.
I am sorting users by the number of users they have invited. I am sorting like this:
const x = await prisma.user.findMany({
select: {
…

Farhan Haider
- 105
- 5
5
votes
3 answers
Prisma2 Error: Invalid `prisma.post.create()` invocation: Unknown arg `tags` in data.tags for type PostUncheckedCreateInput
I want to create a post with a list of tags attached to it. The models are connected many-to-many (one post can have several tags, and one tag can have several posts in it).
Here are my prisma models:
model Post {
id String @id @default(cuid())
…

lumenwrites
- 1,287
- 4
- 18
- 35
5
votes
3 answers
Explicit many to many relation prisma
I have these 3 prisma models,
model user {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
…

Farrukh Faizy
- 1,203
- 2
- 18
- 30
5
votes
1 answer
Map over collection to upsert into the database. How to batch upsert?
Say, I have a data structure coming in from the frontend as follows:
const userData = [
{
id: 11223,
bb: [
{
id: 12,
},
{
id: 34,
bbb: "bbb",
},
],
},
{
id:4234,
...
…

Kayote
- 14,579
- 25
- 85
- 144
4
votes
2 answers
How to integrate prisma with serverless framework aws-nodejs-typescript template
I am building a serverless function using the serverless framework. However im having an issue with running it locally
Error: ENOENT: no such file or directory,
open…

Kay
- 17,906
- 63
- 162
- 270
4
votes
1 answer
How to use where in in Prisma?
I have made a query below that search user using two columns. But it seems not working properly, I assume it is querying the where clause in each column instead of both columns.
Is there a way we could where ~ in for two or more columns?
const users…

tempra
- 2,455
- 1
- 12
- 27
4
votes
1 answer
prisma generate throws TypeError: collection is not iterable
I'm using typescript w/ prisma and when I try to run prisma generate, it keeps throwing
TypeError: collection is not iterable.
at keyBy (/node_modules/@prisma/client/generator-build/index.js:57685:21)
at Object.getTypeMap…

Jeong
- 93
- 6
4
votes
1 answer
prisma 2 testing -- TypeError: Cannot read property '_isMockObject' of undefined
I'm trying to set up my testing environment using the Prisma docs and it's been a bit of a trainwreck. So, I'm working backward trying to figure out why it's not working. I have the setup of the singleton.ts file shown below, and when I try initiate…

kevin
- 2,707
- 4
- 26
- 58
4
votes
1 answer
Prisma - How to use count as a where condition with relation
I use nestjs and postgresql with prisma. I have 2 tables in relation, I want to create a where clause in order to fetch the records if count of the records in the second table is less than -let's say- 3. More details;
Here is my schema
model User {
…

Flardryn
- 457
- 1
- 10
- 25
4
votes
2 answers
Prisma Issue of managing instances of Prisma Client actively running
I'm new to Prisma and Nodejs
I accidentally created lots of instances of Prisma Client that keep displaying the warning of
warn(prisma-client) There are already 10 instances of Prisma Client actively running.
Even I tried to delete old files and…

KickAxe
- 149
- 2
- 13