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.

uuid_to_bin function with swap flag cause Null constraint error in MySQL in prisma v4

See original GitHub issue

Bug description

If I use uuid_to_bin function along with the 2nd parameter swap flag in dbgenerated, when I create a new row, I get a null-constraint error in Prisma v4.4.

This is related to #12850 issue that was raised for v3 versions of Prisma.

How to reproduce

Use Prisma v4.4:

✅ no error:

model A {
  id String @id @default(dbgenerated("(uuid())")) @db.VarChar(36)
}

❌ error:

model B {
  id Bytes @id @default(dbgenerated("(uuid_to_bin(uuid(), 1))")) @db.Binary(16)
}

Expected behavior

No response

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
}

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

model A {
  id             Bytes @id @default(dbgenerated("(uuid_to_bin(uuid(), 1))")) @db.Binary(16)
}

Update: The schema that is erroring out contained dbgenerated("(uuid_to_bin(uuid(), true))") and not dbgenerated("(uuid_to_bin(uuid(), 1))"). Swapping true for 1 made it work for me.

export const test = async () => {
  await prisma.a.create({ data: {} });
}

Environment & setup

  • OS: macOS
  • Database: MySQL
  • Node.js version: v16.17.1

Prisma Version

prisma                  : 4.4.0
@prisma/client          : 4.4.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6
Default Engines Hash    : f352a33b70356f46311da8b00d83386dd9f145d6
Studio                  : 0.474.0
Preview Features        : interactiveTransactions

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sidvenucommented, Oct 17, 2022

Hey folks,

So I copy pasted the schema that is error-ing out wrongly. Here’s the erroring out schema:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
}

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

model A {
  id             Bytes @id @default(dbgenerated("(uuid_to_bin(uuid(), true))")) @db.Binary(16)
}

I realised substituting true for the value 1 makes it work perfectly in my local - but true and 1 from a MySQL perspective should be the same.

I can close this issue because dbgenerated("(uuid_to_bin(uuid(), 1))") works for me - but we potentially might want to keep this issue open to tackle dbgenerated("(uuid_to_bin(uuid(), true))") not functioning as expected.

1reaction
sidvenucommented, Oct 10, 2022

Yup. I used db push to migrate the DB.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dbgenerated function cause Null constraint error in MySQL
Bug description Some dbgenerated functions work and others produce errors. The error is not on the database side, but on Prisma Client side....
Read more >
Prisma schema API (Reference)
API reference documentation for the Prisma Schema Language (PSL).
Read more >
Error message reference - Prisma
Prisma Client throws a PrismaClientUnknownRequestError exception if the query engine returns an error related to a request that does not have an error...
Read more >
Referential actions - Prisma
For example, using SetNull on a required relation will lead to database errors when deleting referenced records because the non-nullable constraint would be ......
Read more >
Handling exceptions and errors (Reference) - Prisma
User ; 2 id Int ; 3 email String ; 4 name String ; 5}.
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