Using validations as constraints
There are certain validations that Sequelize will use as both a validation and a constraint. These parameters are configurable in the attribute’s options as a sibling to the validate
parameters. Constraints are defined and guarded by the database, whereas a validation will be handled by Sequelize and the Node.js runtime exclusively. Here is a list of constraints made available from Sequelize.
allowNull
The allowNull
option will determine whether to apply NOT NULL
to the definitions of columns for the database. The default value is true
, which will allow columns to have a value of null
. There are a couple of caveats to keep in mind when using validations with the allowNull
constraint:
- If the
allowNull
parameter is set tofalse
and the attribute’s value isnull
, then the custom validations will not run. Instead, a ValidationError will be returned without making a request to the database. - If the
allowNull
parameter is set...