uuid_to_bin function with swap flag cause Null constraint error in MySQL in prisma v4
See original GitHub issueBug 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:
- Created a year ago
- Comments:8 (3 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
Hey folks,
So I copy pasted the schema that is error-ing out wrongly. Here’s the erroring out schema:
I realised substituting
true
for the value1
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 tackledbgenerated("(uuid_to_bin(uuid(), true))")
not functioning as expected.Yup. I used
db push
to migrate the DB.