prisma: Cannot update a table - code: 'P2021'
Bug description
I cannot update a table in my postgres database with Prisma. I can read it, create but cannot update this particular table. I can update this table with an SQL query. So I don’t believe that the problem is the table or the schema. This seems to be a bug in Prisma.
unknown database error: { [Error:
Invalid `prisma.user.update()` invocation:
The table `(not available)` does not exist in the current database.]
code: 'P2021',
clientVersion: '3.10.0',
meta: { table: '(not available)' } }
How to reproduce
This prisma query fails with the above error:
await db.user.update({
where: { id: uid },
data: {
avatar: uuid,
images: {
create: [
{
id: uuid,
},
],
},
},
});
This prisma query succeeds (provided I’ve already created this row):
await db.image.update({
where: { id: uuid },
data: {
userId: uid,
},
});
Other queries on the user table succeed: db.user.create
etc
Expected behavior
I expect an update query to succeed. And if I does fail I expect an error message that can tell me why it has failed. This error message is telling me the table '(not available)'
doesn’t exist. Which is just false.
Prisma information
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
model User {
insertedAt DateTime @default(now()) @map("inserted_at")
updatedAt DateTime @updatedAt @map("updated_at")
id String @id @default(cuid())
firstName String @map("first_name") @db.VarChar(40)
lastName String @map("last_name") @db.VarChar(40)
email String @unique @db.VarChar(255)
title String? @db.VarChar(100)
bio String? @db.VarChar(600)
avatar String? @db.VarChar(36)
images Image[]
@@map("users")
}
model Image {
insertedAt DateTime @default(now()) @map("inserted_at")
updatedAt DateTime @updatedAt @map("updated_at")
id String @id
userId String @map("user_id")
user User @relation(fields: [userId], references: [id], onDelete: Restrict, onUpdate: Cascade)
@@index([userId])
@@map("images")
}
Environment & setup
- OS: Mac OS 12.2.1
- Database: PostgreSQL
- Node.js version: 16.14.0
Prisma Version
prisma : 3.10.0
@prisma/client : 3.10.0
Current platform : darwin-arm64
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio : 0.458.0
Preview Features : referentialIntegrity
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 23 (9 by maintainers)
thanks as you suggest, the fix is to remove
referentialIntegrity = "prisma"
rebuild the client then put it back in and rebuild the client again 😃I’m using this is in a postgres DB because I’m in the process of migrating to PlanetScale and I want to confirm things work before migrating
sorry! It’s Supabase
I can’t sorry, it fixed itself by doing the above. If it breaks again in the same way I’ll let you know
Thanks! The problem is actually simpler than a nested create. I’ve simplified things: This fails:
While the same query as raw sql succeeds: