`@default` doesnt work for enum
See original GitHub issueI have this datamodel:
model User {
id: Int @id
name: String
role: Role @default(USER)
posts: Post[]
}
model Post {
id: Int @id
title: String
author: User
}
enum Role {
USER
ADMIN
}
Because role
has a default
value, it can be omitted in the Photon API call:
import { Photon } from '@generated/photon'
const photon = new Photon()
async function main() {
await photon.connect()
const result = await photon.users.create({
data: { name: 'Niko' }
})
console.log(result)
photon.close()
}
main().catch(e => {
console.error(e)
photon.close()
})
When I execute this code, I get the following error:
$ yarn start
yarn run v1.13.0
$ ts-node main.ts
PhotonError: [
{
"error": "ConnectorError(NullConstraintViolation { field_name: \"User.role\" })"
}
]
at NodeEngine.handleErrors (/Users/nikolasburk/Desktop/prisma2-test/node_modules/@generated/photon/runtime/index.js:1308:15)
at /Users/nikolasburk/Desktop/prisma2-test/node_modules/@generated/photon/runtime/index.js:1283:37
at processTicksAndRejections (internal/process/task_queues.js:89:5) {
query: 'mutation {\n createUser(data: {\n ' +
'name: "Niko"\n }) {\n id\n name\n }\n' +
'}',
error: [
{
error: 'ConnectorError(NullConstraintViolation { field_name: "User.role" })'
}
],
logs: '[query-engine/core/src/builders/mutations/root.rs:179] &model.models() = ' +
'[\n Model {\n name: "User",\n stable_identifier: "",\n ' +
' is_embedded: false,\n manifestation: None,\n fields: ' +
'OnceCell {\n once: Once {\n state: Done\n ' +
' },\n value: UnsafeCell\n },\n ' +
'internal_data_model: #InternalDataModelWeakRef#\n },\n Model {\n ' +
' name: "Post",\n stable_identifier: "",\n is_embedded: ' +
'false,\n manifestation: None,\n fields: OnceCell {\n ' +
' once: Once {\n state: Done\n },\n ' +
'value: UnsafeCell\n },\n internal_data_model: ' +
'#InternalDataModelWeakRef#\n }\n]\n' +
'[query-engine/connectors/sql-connector/src/database/sqlite.rs:54] ' +
'visitor::Sqlite::build(q) = (\n "INSERT INTO `migration_engine`.`User` ' +
'(`name`) VALUES (?)",\n [\n Text(\n "Niko"\n )\n ' +
' ]\n)\n',
isPanicked: false
}
✨ Done in 1.25s.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (6 by maintainers)
Top Results From Across the Web
What is the default value for enum variable? - Stack Overflow
The default value of an enum E is the value produced by the expression (E)0 . As an example, take the following enum:...
Read more >`@default` doesnt work for enum · Issue #33 · prisma ... - GitHub
I have this datamodel: model User { id: Int @id name: String role: Role @default(USER) posts: Post[] } model Post { id: Int...
Read more >UnnecessaryDefaultInEnumSwitch - Error Prone
UnnecessaryDefaultInEnumSwitch. Switch handles all enum values: an explicit default case is unnecessary and defeats error checking for non-exhaustive switches.
Read more >MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column...
Read more >Postgres / Enum / Default enum value can't be inserted via ...
Create an ENUM in Postgres with a few options. Create a table, where one of the columns will be enum's type, and has...
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 Free
Top Related Reddit Thread
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
I like the second one (
Role.USER)
. It kinda weirds me out that enum values are effectively global in Prisma 1.x.How about support of array values in default
@default([value1, value2, ...])
?An example could be if a user can have multiple roles: