-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Configure a list with an integer autoincrement field
import { list } from "@keystone-6/core";
import { integer } from "@keystone-6/core/fields";
list({
fields: {
no: integer({
defaultValue: { kind: "autoincrement" },
db: { isNullable: false }, // if this is not set I get a prisma error
}),
}
});
Prisma Error when db.isNullable is not set to false
Error loading your Keystone config Error: Request.no specifies defaultValue: { kind: 'autoincrement' } but doesn't specify db.isNullable: false. Having nullable autoincrements on Prisma currently incorrectly creates a non-nullable column so it is not allowed. https://github.com/prisma/prisma/issues/8663
I also tried validation: { isRequired: false}
When you try to create a new record for this list it will return an validation error for a missing value on that field:
You provided invalid data for this operation. - Request.no: missing value

I setup the integer field like described in the docs:
defaultValue (default: undefined): Can be either an integer value or { kind: 'autoincrement' }. This value will be used for the field when creating items if no explicit value is set. { kind: 'autoincrement' } is only supported on PostgreSQL.
I should not need to put in a value for that field on any db operation because it is configured to auto-increment. When I put in a value into the integer field this value will be saved. What am I missing or is this a bug?
My db config
...
db: {
provider: "postgresql",
url: `postgres://${process.env.DB_USER}:${process.env.DB_PASS}@localhost:5432/keystone`,
enableLogging: false,
idField: { kind: "uuid" }, // is it because of this??!
shadowDatabaseUrl: `postgres://${process.env.DB_USER}:${process.env.DB_PASS}@localhost:5432/shadowdb`,
},
...
node version v20.18.1
brave browser v1.74.50
postgresql v17.2
keystone-6/core v6.3.1