Questions tagged [prisma]
Prisma is a next-generation Node.js and TypeScript ORM for PostgreSQL, MySQL, SQLite, CockroachDB, MongoDB and SQL Server.
3,306
questions
35
votes
1
answer
51k
views
Prisma : how can I find all elements that match an id list?
I am using Prisma with NextJs.
In my API, I send to the back end a list of numbers that correspond to id's of objects in my database.
As an example, if I receive the list [1, 2, 12], I would like to ...
30
votes
7
answers
44k
views
prisma - getting environment variable not found error message when running graphql query
I am getting this error message from prisma when I am running the GraphQL query.
Environment variable not found: DATABASE_URL.\n --> schema.prisma:6\n | \n 5 | provider = \"postgresql\&...
30
votes
8
answers
34k
views
get full type on prisma client
When i generate my prisma client with prisma generate, i got an index.d.ts with all types from my database.
But the probleme is that all type are "single" and there is no relations.
When i ...
28
votes
4
answers
38k
views
How to upsert new record in Prisma without an ID?
I'm using Prisma (https://www.prisma.io) as ORM. I want to check for duplicates when store data and, if not exists, create a new record.
I thought I could do that with upsert method provided by ...
27
votes
2
answers
39k
views
How to get enums in prisma client?
can I get a list of enums values of a model on the client-side like for select option?
Sample enum
enum user_type {
superadmin
admin
user
}
I want this as a select-option on the client-...
26
votes
5
answers
21k
views
M1 Related! - Prisma: Can't reach database server at `database`:`5432`
Since I have moved to the new Apple Silicon architecture my docker setup with nextjs and postgres is not working anymore. The database inside the docker cannot be found by the nextjs server where I am ...
24
votes
3
answers
20k
views
docker and mysql: Got an error reading communication packets
I have a problem with connectivity in docker. I use an official mysql 5.7 image and Prisma server. When I start it via prisma cli, that uses docker compose underneath (described here) everything works....
22
votes
8
answers
43k
views
@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again
I am using prisma, postgres, docker, kubernets.
npx prisma migrate dev working.
and npx prisma generate produce below output:
✔ Generated Prisma Client (2.23.0) to ./node_modules/@prisma/client in ...
21
votes
13
answers
26k
views
"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 ...
21
votes
6
answers
17k
views
Reason: `object` ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types
I am using Prisma and Next.js. When I try to retrieve the content from Prisma in getStaticProps it does fetch the data but I can't pass it on to the main component.
export const getStaticProps = async ...
21
votes
4
answers
25k
views
Difference between prisma db push and prisma migrate dev
what is the difference between prisma db push and prisma migrate dev ? When should I use one over the other. Docs say that prisma db push is about schema prototyping only and I don't understand what ...
20
votes
3
answers
51k
views
Run MySQL on Port 3307 Using Docker Compose
I am trying to create multiple Prisma database services on a single machine. I have been unable to create a MySQL database on a port other than 3306 using Docker Compose.
docker-compose.yml
...
20
votes
2
answers
14k
views
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?
19
votes
9
answers
26k
views
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 ...
19
votes
3
answers
24k
views
I want to use multiple database in prisma orm
I am not able to use multiple database in same application . How can we use multiple data sources.
Can we generate multiple "schema.prisma" for different database connections.
18
votes
5
answers
13k
views
prisma can't connect to postgresql
I've tried to connect Prisma with postgreSQL several times.
prisma show this error message : "Error: undefined: invalid port number in "postgresql://postgres:password@localhost:5432/linker&...
18
votes
6
answers
24k
views
Get User ID from session in next-auth client
I'm using next-auth with Prisma and Graphql, I followed these instructions to set up the adapter and my models accordingly:
https://next-auth.js.org/adapters/prisma
Authentication works but when I ...
16
votes
1
answer
32k
views
Nexus Prisma - How to handle createdAt and updatedAt with crud globally?
First thing I came up with, is by calling computedInputs in the nexusPrisma option. But it won't work since they need to be handled differently depending on the situation, but globally:
1. create ->...
16
votes
3
answers
9k
views
Unknown binaryTarget debian-openssl-3.0.x and no custom binaries were provided error Command failed with exit code 1
Is there any way I can solve this problem? I recently updated to Ubuntu 22.04
Getting the problem while using Prisma.I can't run my project. I have use "@prisma/client": "2.20.1"
...
16
votes
5
answers
49k
views
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 ...
16
votes
2
answers
22k
views
WebSocket connection to 'ws:<URL>/_next/webpack-hmr' failed: WebSocket is closed before the connection is established
Hi am having this problem, i try to make subscriptions with graphql in nextjs, but something is wrong and i dont have any idea how fix it. I am having websocket error - "WebSocket connection to '...
15
votes
2
answers
12k
views
Ordering by multiple columns in Prisma
I know currently Prisma doesn't support ordering by multiple scalars fields, (see this issue: https://github.com/prisma/prisma/issues/62).
But, I'm wondering if there is someone who found a solution ...
15
votes
1
answer
2k
views
Typescript circular reference when testing prisma with jest-mock-extended
I started writting tests revolving around prisma(v3.6.0) usage in my application.
To do so I followed the official prisma page Unit testing with prisma and I am using jest-mock-extended.
My issue is ...
14
votes
1
answer
6k
views
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 ...
14
votes
1
answer
4k
views
Use prisma generated types with swagger nestjs
I am using nestjs with prisma and swagger. When I use
import {PrismaGeneratedType} from '@prisma/client';
...
@ApiOkResponse({type: PrismaGeneratedType})
in a controller if gives error:
'...
13
votes
2
answers
20k
views
Prisma $queryRaw with variable length parameter list
I am using Prisma with Postgres. I need to use $queryRaw for a particular query due to use of unsupported tsvector type in the underlying table. In this query, I also need to use an 'in' statement ...
13
votes
1
answer
25k
views
Why "null" can't be the default value of a nullable column?
Consider this schema:
model Comment {
id Int @id @default(autoincrement())
reply Comment? @relation(fields: [replyId], references: [id], onDelete: SetNull)
replyId Int? ...
13
votes
2
answers
27k
views
Querying NOT NULL GraphQL with Prisma
Schema:
type TrackUser {
id: ID! @unique
createdAt: DateTime!
user: User #note there is no `!`
}
type User {
id: ID! @unique
name: String! @unique
}
I want to get Alls TrackUser where User ...
13
votes
5
answers
16k
views
How to split Prisma Model into separate file?
I'm learning Prisma ORM from video tutorials and official docs. They are explain and write All model code in one file called schema.prisma. It's ok but, when application grow it became messy. So, how ...
12
votes
3
answers
29k
views
Error when migrating models to database Prisma
I'm starting a project where I have to learn a new technology and I chose to build a full-stack app with Prisma and Next.js. I'm using both for the first time. I've built front-end apps w/ React.js ...
12
votes
6
answers
13k
views
Supabase client permission denied for schema public
Whenever I've try to use @supabase/supabase-js to query the db, I get an error.
error: {
hint: null,
details: null,
code: '42501',
message: 'permission denied for schema public'
}
I ...
12
votes
3
answers
20k
views
How do I use next auth getServerSession in next js 13 beta server component in app directory
I'm using next auth v4 with next js 13 beta with server component, and everything works fine. But I have a situation where I will need to know the logged user id, since I'm using next auth, I have ...
11
votes
1
answer
12k
views
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 ...
11
votes
2
answers
34k
views
Timestamp with timezone column in Prisma
I am evaluating Prisma and I am a complete noob...
I am using Postgresql
I have the following model definition
model Sth {
id Int @default(autoincrement()) @id
createdAt ...
11
votes
3
answers
13k
views
Testing a NestJS Service that uses Prisma without actually accessing the database
Most examples I've seen of how to test a Prisma-injected NestJS Service (e.g. prisma-sample in testing-nestjs) are for "end to end" testing. They actually access the database, performing ...
11
votes
1
answer
11k
views
How to find or create a record with Prisma?
Is this the best way to find or create a user in Prisma?
prisma.user.upsert({
where: {
id: user.id,
},
update: {
id: user.id,
},
create: {
id: user.id,
},
})
11
votes
5
answers
47k
views
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 ...
11
votes
1
answer
11k
views
One-to-many self-relation in prisma schema
I want to create a simple table:
Users
---
id
name
friends
friends field should be an array of other user ids. I'm trying to define a schema for this in schema.prisma:
model User {
id String @...
11
votes
1
answer
14k
views
Prisma deleteMany with a list of IDs
I'm wondering if there is a way in the Prisma Client to batch delete database records by id.
Something like this doesn't seem to exist:
const idsToDelete = [5, 29, 255]
prisma.post.deleteMany({
...
11
votes
2
answers
34k
views
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 ...
11
votes
2
answers
15k
views
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())
}
...
11
votes
1
answer
10k
views
Prisma how can I update only some of the models fields in update()
I have a Prisma model with lets say 10 fields.
Think User model with firstname, lastname, address, e-mail , phone, mobile, age etc.
I am trying to write a update method for this, where I most of the ...
11
votes
3
answers
7k
views
How to set environment variables with Prisma, Nextjs, and Vercel
Nextjs wants you to use a .env.local file to store env vars.
Prisma uses .env
If I use a .env.local file then setting up the Prisma db
datasource db {
provider = "postgresql"
url = ...
11
votes
3
answers
17k
views
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 ...
10
votes
3
answers
14k
views
Data modeling in Prisma with relations
I have a problem understanding relations and data-modeling in Prisma. I have an "easy" example about two users who can participate in a tennis game. So i have:
Model User {
id Int @id ...
10
votes
1
answer
11k
views
DateTime without time / only data? It is possible in Prisma?
I can in Prisma create columns without data, without time?
my model at the moment:
model modelName {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
...
10
votes
1
answer
13k
views
How to make id autoincrement in schema.prisma?
I am writing a postgreSQL database. The ID must be auto-incrementing.
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified ...
10
votes
2
answers
10k
views
Which is better - Int autoincrement id or cuid for PostgreSQL prisma schema?
We use Postgres and prisma for our Next.js app. Previous developers have used cuid for every table on our schema. For some reasons we are restructuring the tables and I was wondering would it be ...
10
votes
4
answers
23k
views
Error: P1001: Can't reach database server at `localhost`:`5200`
Technologies I use:
nestjs -> for backend
prisma -> for orm
postgresql -> database
I'm trying to run these technologies using Docker but I'm running into the following issue:
prisma schema ...
10
votes
2
answers
20k
views
Update multiple rows using Prisma without manual loops
I have following prisma.schema:
model Tag {
id Int @id @default(autoincrement())
name String @unique
files FileTag[]
}
model FileTag {
tag Tag @relation(fields: [tagId], ...