dbgenerated function cause Null constraint error in MySQL
See original GitHub issueBug description
Some dbgenerated functions work and others produce errors. The error is not on the database side, but on Prisma Client side.
How to reproduce
✅ no error:
model A {
id Bytes @id @default(dbgenerated("(uuid_to_bin(uuid()))")) @db.Binary(16)
}
❌ error:
model B {
id Bytes @id @default(dbgenerated("(uuid_to_bin(uuid(), 1))")) @db.Binary(16)
}
error detail:
Null constraint violation on the (not available)
code: 'P2011',
clientVersion: '3.12.0',
meta: { constraint: null }
Expected behavior
Because the value is generated on the db side, there is no need to detect errors in Prisma Client.
Prisma information
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity", "fullTextIndex", "fullTextSearch", "interactiveTransactions", "filterJson"]
}
model A {
id Bytes @id @default(dbgenerated("(uuid_to_bin(uuid()))")) @db.Binary(16)
}
model B {
id Bytes @id @default(dbgenerated("(uuid_to_bin(uuid(), 1))")) @db.Binary(16)
}
export const test = async () => {
await prisma.a.create({ data: {} })
await prisma.b.create({ data: {} })
}
Environment & setup
- OS: Mac OS
- Database: MySQL
- Node.js version: v16.14.0
Prisma Version
prisma : 3.12.0
@prisma/client : 3.12.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 22b822189f46ef0dc5c5b503368d1bee01213980
Studio : 0.459.0
Preview Features : referentialIntegrity, fullTextIndex, fullTextSearch, interactiveTransactions, filterJson
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
MYSQL ignores not null constraint, inserts null values into ...
I have learnt how MYSQL NOT NULL CONSTRAINT, and the SQL STRICT MODE ... explicit NULL values into the column, MYSQL will throw...
Read more >Prisma schema API (Reference)
Specify a MySQL data source. In this example, the target database is available with the following credentials: User: johndoe; Password: mypassword ...
Read more >The ultimate guide on DB-generated IDs in JPA Entities
The ultimate guide on DB-generated IDs in JPA Entities. ... If sequences are not supported (i.e., we use MySQL), it will use TABLE...
Read more >MySQL NOT NULL Constraint
It's a good practice to have the NOT NULL constraint in every column of a table unless you have a good reason not...
Read more >Prisma 3.15.0 Release - GitClear
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, ... dbgenerated function cause Null constraint error in MySQL ...
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
@janpio done - #15727
Thank you for your quick response. We have confirmed that the following version works correctly.
No errors. Thank you!