keystone
keystone copied to clipboard
Default value automatically set for MySQL TEXT field
I want to create a text field wich allows more than 191 charracters. So when i create a textfield and change its native type to be a MySQL TEXT field. The following error occurs upon running the migration due to setting the field property isNullable to false.
Database error: BLOB, TEXT, GEOMETRY or JSON column 'coverText' can't have a default value
The database model:
coverText: text({
validation: {
isRequired: true,
length: {
min: 1,
max: 1000
}
},
db: {
nativeType: 'Text',
isNullable: false,
},
ui: { displayMode: 'textarea' }
}),
In the sourcecode I can see that when the property isNullable is set, a defaultValue of '' will be set in the following line:
const defaultValue = isNullable === false || _defaultValue !== undefined ? _defaultValue || '' : undefined;
https://github.com/keystonejs/keystone/blob/e18659a78bdb2a5ed7e64604e168cc98fe8f3a9e/packages/core/src/fields/types/text/index.ts#L106
Because a default value may not be set for a MySQL field with type Text, and I don't want to make the field nullable it is impossible to have the option to make a text field with the following properties:
db: {
nativeType: 'Text',
isNullable: false
}
Proposal:
Add a feature to KeystoneJS that allows for the creation of non-nullable MySQL TEXT fields without default values.