question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Field does not exist on enclosing type" / Relation tables bug

See original GitHub issue

Bug 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:open
  • Created 2 years ago
  • Reactions:7
  • Comments:115 (22 by maintainers)

github_iconTop GitHub Comments

14reactions
chrisjingramcommented, Feb 1, 2022

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 caches

find . -name .prisma

For me this returned

./node_modules/.prisma
./node_modules/.cache/nx/4eed8695dacb1a0791560527d1349b02482e356ecd914b8f5b6a04b136d8afcc/outputs/dist/packages/app/node_modules/.prisma
./node_modules/.cache/nx/b817ddbda9e0f7f96e31d2026e51b70340b23febeef0d9b4c629ded7526f39c3/outputs/dist/packages/app/node_modules/.prisma
./node_modules/.cache/nx/3f0333ed9f8580046ca58f9c687d609aa91551c4c539e5fb442677a5bd52802e/outputs/dist/packages/app/node_modules/.prisma

Delete node_modules/.prisma and node_modules/.cache directory, and then regenerate prisma client

rm -rf node_modules/.prisma
rm -rf node_modules/.cache
npx prisma generate

Working again for me 🎉

11reactions
janpiocommented, Nov 25, 2021

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):

  1. Run npx prisma -v in your project directory and store the full output of that
  2. Set the env var DEBUG=*, full instructions at https://pris.ly/d/debugging
  3. Enable full logging in PrismaClient, instructions at https://pris.ly/d/logging
  4. Start you application and run the problematic query. Copy all the output from your terminal and store it somewhere. (Might be quite a lot depending on your application - that is fine).

Then 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found