prisma: Invalid `….findMany()` invocation: The column `j1.id` does not exist in the current database.

Bug description

After updating to 5.4.0, the following error is shown when running the command provided below with the schema provided below:

prisma:query SELECT "public"."Post"."id" FROM "public"."Post" LEFT JOIN "public"."User" AS "j1" ON ("j1"."email") = ("public"."Post"."email") WHERE ("j1"."email" = $1 AND ("j1"."id" IS NOT NULL)) OFFSET $2
prisma:error 
Invalid `prisma.post.findMany()` invocation in
…/prisma21352/src/index.ts:14:33
…
→ 14 console.log(await prisma.post.findMany(
The column `j1.id` does not exist in the current database.

How to reproduce

See also: https://github.com/marvinruder/prisma21352

Run

await prisma.post.findMany({
  select: {
    id: true,
  },
  where: {
    user: {
      email: 'alice@example.com',
    }
  }
})

with client generated from the provided schema.

Expected behavior

All watchlist rows related to the specified user (identified by their email) are returned.

Prisma information

// Add your schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  email String      @id @db.VarChar(255)
  posts Post[]
}

model Post {
  id    Int     @id @default(autoincrement())
  user  User    @relation(fields: [email], references: [email], onUpdate: Cascade, onDelete: Cascade)
  email String  @db.VarChar(255)
}
// Add your code using Prisma Client
await prisma.post.findMany({
  select: {
    id: true,
  },
  where: {
    user: {
      email: 'alice@example.com',
    }
  }
})

Environment & setup

  • OS: occurring on macOS 14.0 (build 23A344) and in node:20.8.0-alpine Docker image
  • Database: PostgreSQL
  • Node.js version: 20.8.0

Prisma Version

prisma                  : 5.4.0
@prisma/client          : 5.4.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine a5596b96668f0f4b397761ce0956db54e17e48c4 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli a5596b96668f0f4b397761ce0956db54e17e48c4 (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.4.0-47.a5596b96668f0f4b397761ce0956db54e17e48c4
Default Engines Hash    : a5596b96668f0f4b397761ce0956db54e17e48c4
Studio                  : 0.494.0

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 8
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

We are working on a fix now and hope to release it as a patch soon.

Hey @marvinruder @Eldemarkki @chrishoermann, although we are pretty confident we fixed the problem, we would love if you could try out 5.4.1 and report back if this indeed fixed the problem for you. Thank you.

Yes, everything works fine after upgrading to 5.4.1 in my project. Thanks for the quick patch!

Works on my end too! Thanks!

Hey everyone 👋 and thanks for your reports. The fix is now available in our latest patch release. https://github.com/prisma/prisma/releases/tag/5.4.1

Thanks, we have a confirmed reproduction internally as well.

Works for me also, thanks!

A minimal reproduction repository is now provided at https://github.com/marvinruder/prisma21352.

part of my schema


generator client {
    provider        = "prisma-client-js"
}

generator zod {
    provider                         = "zod-prisma-types"
    useMultipleFiles                 = true
    createOptionalDefaultValuesTypes = true
    createRelationValuesTypes        = true
    writeNullishInModelTypes         = true
    addSelectType                    = false
    addIncludeType                   = false
}

datasource db {
    provider  = "postgresql"
    url       = env("POSTGRES_PRISMA_URL") // uses connection pooling
    directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}


// CITY
//------------------------------------------------------

/// City => "Ort/Stadt"
model City {
    cityRefNumber      String    @id /// Gemeindekennziffer 
    city               String
    zipCode            String
    additionalZipCodes String[]
    districtRefNumber  String /// foreignKey
    villages           Village[] // villages connected to this city
    district           District  @relation(fields: [districtRefNumber], references: [districtRefNumber])

    companies          Company[] // companies that have a license for this city
    applicantAddresses ApplicantAddress[]

    @@unique([cityRefNumber, districtRefNumber])
}

// DISTRICT
//------------------------------------------------------

/// District => "Bezirk"
model District {
    districtRefNumber String @id /// "Bezirkskennzahl" 
    district          String @unique
    stateRefNumber    String /// foreignKey
    cities            City[]
    state             State  @relation(fields: [stateRefNumber], references: [stateRefNumber])

    companies Company[] // companies that have a license for this district

    @@unique([districtRefNumber, stateRefNumber])
}

// STATE
//------------------------------------------------------

/// State => "Bundesland"
model State {
    stateRefNumber String     @id /// "Bundeslandkennzahl"
    state          String     @unique
    countryCode    String /// foreignKey
    districts      District[]
    country        Country    @relation(fields: [countryCode], references: [countryCode])
    Company        Company[]

    @@unique([stateRefNumber, countryCode])
}

// COUNTRY
//------------------------------------------------------

/// Country => "Staat"
model Country {
    countryCode String  @id
    country     String  @unique
    states      State[]
}

/////////////////////////////////////////
// COMPANY DATA
/////////////////////////////////////////

// @zod.import(["import validator from "validator";"])
model Company {
    id String @id @default(cuid())

    companyName           String?
    registeredCompanyName String?
    lastName              String?
    firstName             String?
    postGraduateTitle     String?
    title                 String?
    email                 String? /// @zod.string.email()
    homepage              String?
    phoneNumber           String?
    mobilePhone           String?
    faxNumber             String?
    street                String
    houseNumber           String
    houseNumberAddition   String?
    zipCode               String
    city                  String
    cityRefNumber         String?
    villageRefNumber      String?
    stateRefNumber        String?
    latitude              Float?
    longitude             Float?
    vacantJobs            Int? /// @zod.custom.use(z.union([z.number(), z.nan()]).transform((v) => (Number.isNaN(v) ? null : v)).optional()) 

    userId        String?
    user          User?              @relation(fields: [userId], references: [id])
    isInCity      City?              @relation(fields: [cityRefNumber], references: [cityRefNumber])
    isInVillage   Village?           @relation(fields: [villageRefNumber], references: [villageRefNumber])
    isInDistricts District[]
    isInStates    State?             @relation(fields: [stateRefNumber], references: [stateRefNumber])
    applicants    CompetitionEntry[]
}

I think this is it

prisma:query SELECT "public"."RecipesOnCollections"."recipeId", "public"."RecipesOnCollections"."recipeCollectionId", "public"."RecipesOnCollections"."createdAt" FROM "public"."RecipesOnCollections" LEFT JOIN "public"."RecipeCollection" AS "j1" ON ("j1"."id") = ("public"."RecipesOnCollections"."recipeCollectionId") WHERE ("public"."RecipesOnCollections"."recipeId" = $1 AND ("j1"."userId" = $2 AND ("j1"."recipeId" IS NOT NULL AND "j1"."recipeCollectionId" IS NOT NULL))) OFFSET $3