Ad
Sequelize Unique Custom Message
When I try to define a custom message, the default message Validation error
still appears.
The unique
property accepts either a boolean or an object
whit properties name
and msg
. What does name
mean? Why don't I see the message in msg
?
sequelize: 6.16.1
Thank you
idcustomer: {
type: DataTypes.STRING(255),
allowNull: false,
primaryKey: true,
unique: {
name: 'idcustomer',
msg: 'idcustomer duplicate',
},
validate: {
notEmpty: {
msg: RequiredFieldMessage('Id Customer'),
},
},
},
Ad
Answer
unique
is a constraint and makes sense in DB unlike validate
option that is used by Sequelize only.
See validations and constraints
I suppose name
and msg
is for cases when a DB will throw SequlizeUqniueConstraint error.
Ad
source: stackoverflow.com
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad