"Field does not exist on enclosing type" / Relation tables bug
See original GitHub issueBug description
I have some Question for prisma2 join table. and also one issue
- Schema:
//other
model LayoutSetting {
id Int @id @default(autoincrement())
order Int
route String @db.VarChar(255)
category LayoutSettingCategory @default(CategoryListRow)
title String @unique @db.VarChar(255)
relatedLayoutToProduct LayoutSettingLinkProduct[]
}
model LayoutSettingLinkProduct {
layoutId Int
productId Int
order Int
layout LayoutSetting @relation(fields: [layoutId], references: [id])
product Product @relation(fields: [productId], references: [id])
@@id([layoutId, productId])
@@index([order])
}
model Product {
id Int @id @default(autoincrement())
order Int
thumb String @db.VarChar(255)
infoURL String @db.VarChar(255)
title String @unique @db.VarChar(255)
desc String @db.VarChar(255)
createAt DateTime @default(now()) @db.DateTime(6)
updateAt DateTime @default(now()) @updatedAt @db.DateTime(6)
levelStart Int
levelEnd Int
language String @db.VarChar(255)
isTrackCollection Boolean @default(false)
infoThumb String @db.VarChar(255)
cover String @db.VarChar(255)
isProductRenewal Boolean @default(false)
//relatedLayoutToProduct LayoutSettingLinkProduct[] (it might be not nesseary need it)
//mediaList MediaCollection[] (it might be not nesseary need it)
//ownedProduct OwnedProduct[] (it might be not nesseary need it)
//tags Tag[]
}
After executing many transactions and queries as a batch program, the following errors occurred.
Invalid prisma.layoutSettingLinkProduct.deleteMany()
invocation:
Failed to validate the query: `Field does not exist on enclosing type.` at `Mutation.deleteManyLayoutSettingLinkProduct`
at cb (/Users/creejee/*****/renewal-project/*********/node_modules/@*****************/appsync-schema/prisma/generated/client/runtime/index.js:36952:17)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async upsertLayout (/Users/creejee/*****/renewal-project/*********/util/batch/appsync/insertProductData.js:59:9)
at async task (/Users/creejee/*****/renewal-project/*********/util/batch/appsync/insertProductData.js:496:9) {
code: 'P2009',
clientVersion: '3.1.1',
meta: {
query_validation_error: 'Field does not exist on enclosing type.',
query_position: 'Mutation.deleteManyLayoutSettingLinkProduct'
}
}
The following sample code was written for problem trouble shooting, and there was no error at this time.
import { PrismaClient } from "./prisma/generated/client";
const prismaClient = new PrismaClient()
const layout = await prismaClient.layoutSetting.create({
data: {
title: "test",
order: 0,
route: "/",
},
});
const product = await prismaClient.product.create({
data: {
cover: "",
desc: "",
infoThumb: "",
infoURL: "",
language: "",
levelEnd: 0,
levelStart: 0,
order: 0,
thumb: "",
title: "",
},
});
if (layout && product) {
await prismaClient.layoutSettingLinkProduct.createMany({
data: {
layoutId: layout.id,
productId: product.id,
order: 1,
},
});
const { count } =
await prismaClient.layoutSettingLinkProduct.deleteMany({
where: {
layoutId: layout.id,
// productId: undefined,
},
});
console.log(count);
}
I don’t know what I need to solve the problem, and I don’t know why there’s no error in the sample code… Is this a bug? Or is it my fault?
How to reproduce
i’m trying reproduce but it does’t error
Expected behavior
it run success
Prisma information
I send it full schema and stdout log schemas@prisma.io
Environment & setup
- OS:
➜ ~ sw_vers
ProductName: macOS
ProductVersion: 11.6
BuildVersion: 20G165
➜ ~ uname
Darwin
- Database: mysql (aurora-serverless with ssh tunneling)
- Node.js version: v16.8.0
Prisma Version
prisma : 3.1.1
@prisma/client : 3.1.1
Current platform : darwin
Query Engine (Node-API) : libquery-engine c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : c22652b7e418506fab23052d569b85d3aec4883f
Studio : 0.423.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:115 (22 by maintainers)
Top Results From Across the Web
Prisma client breaks when I add a field to a model
I assume the Prisma error message (“Field does not exist on enclosing type”) means that Prisma thinks there isn't an avatarCode field on...
Read more >type-graphql/prisma2 - Gitter
I'm running into an issue at the moment when trying to add a relation to a model, I've followed ... Field does not...
Read more >Sqoop User Guide (v1.4.6) - The Apache Software Foundation!
You can use Sqoop to import data from a relational database management system ... To display a list of all available tools, type...
Read more >The jOOQ Release Note History
RETURNING doesn't work with unqualified field templates in SQL Server ... #13792, Data type rewrites to BOOLEAN don't work in Oracle JSON_OBJECT.
Read more >Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Since there was no explicit type mapping, Hibernate looks to the ... SQL by enclosing the table or column name in backticks in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If anyone is still having trouble, for me this was related to Nx monorepo caching the .prisma directory from a previous build. These caches are not easy to spot in your directory tree.
Some quick commands to try:
To find
.prisma
cachesFor me this returned
Delete
node_modules/.prisma
andnode_modules/.cache
directory, and then regenerate prisma clientWorking again for me 🎉
Hey all 20+ people that reported this problem here, as you can see with the labels we still do not have a good idea why this s happening - which is required for us to fix it. And we definitely want, you all staying on 3.0.2 is a workaround, but not something that should become a long term solution.
So, let’s take another look if we can figure this out. Everyone who posted here and still has the problem, please do the following things two times. Once for your project in its working state (with whatever version that was, or 3.0.2 if you went to that) and once with a failing newer version of Prisma (either the current 3.5.0 or whatever you tried before):
npx prisma -v
in your project directory and store the full output of thatDEBUG=*
, full instructions at https://pris.ly/d/debuggingPrismaClient
, instructions at https://pris.ly/d/loggingThen when you have these 2 data bits (version info and log output) for both cases, please post a comment here with the in total 4 output copies or send them to me at
jan@prisma.io
if you do not want to share them publicly.While you are at it, and you are comfortable with that, please archive your full failing project (including your node_modules!) into a zip file, upload it somewhere, and send the link to me at
jan@prisma.io
as well. Maybe we can figure out what is going wrong by looking at the code that is actually running on your computers.I know we are asking for a lot here, but this seems like the only way forward here and to finally hopefully be able to understand what is going on here. Thanks!