Next.js Discord

Discord Forum

Prisma Query error

Unanswered
Tonkinese posted this in #help-forum
Open in Discord
TonkineseOP
Hey guys, I'm getting the following error for this prisma query:
const products = await db.product.findMany({
    where: {
      users: {
        some: {
          userId: {
            equals: user.id
          }
        }
      }
    },
    include: {
      users: {
        include: {
          user: true
        }
      }
    }
  })


Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(PostgresError { code: "42883", message: "operator does not exist: uuid = text", severity: "ERROR", detail: None, column: None, hint: Some("No operator matches the given name and argument types. You might need to add explicit type casts.") }), transient: false })


it's the where part of that query that's causing the error
and Product.id is a UUID

30 Replies

did you run prisma migrate?
TonkineseOP
yeah I'm pretty sure, everything else seems to work, but let me delete my db and re-seed everything just to be sure
yeah it's that specific where clause for some reason
are you using typescript?
TonkineseOP
I am yeah
it's a ⨯ PrismaClientUnknownRequestError: error
don't think it's a ts thing
npx prisma generate ?
TonkineseOP
$ npx prisma generate && npx prisma migrate dev && npx prisma migrate reset is what I ran
it should run generate after migrate
but when you run migrate, it should run generate after for you
TonkineseOP
I mean im not seeing any errors when i run it
how is your schema look like?
@Ray how is your schema look like?
TonkineseOP
like this:
model User {
  id   Int     @id @default(autoincrement())
  slug String  @unique

  products  ProductsOnUsers[]
}

model Product {
  id       String @id @default(uuid()) @db.Uuid
  info      String @unique

  users ProductsOnUsers[]
}

model ProductsOnUsers {
  user   User @relation(fields: [userId], references: [id])
  userId Int
  product      Product    @relation(fields: [productId], references: [id])
  productId    String

  @@id([userId, productId])
}
it should be
model ProductsOnUsers {
  user      User    @relation(fields: [userId], references: [id])
  userId    Int
  product   Product @relation(fields: [productId], references: [id])
  productId String

  @@id([userId, productId])
}
if you are using vscode, I recommend you install the prisma extension
TonkineseOP
ah sorry, it does say userId , pasted it wrong
TonkineseOP
Ok found the issue
specifically id String @id @default(uuid()) @db.Uuid
removing @db.Uuid fixed it
🤷‍♂️
oh cool
well if you use the prisma extension, it should warn you for that
TonkineseOP
I do use it lol, didn't see any warning for that
oh
TonkineseOP
not exactly sure why it was breaking things, but at least it's fixed lol
appreciate the hand man, thank you
np