You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@epsyan Thanks. I have seen that workaround. I expect the Sequelize to be fixed internally, otherwise I would have to use the hook in every schema that is not efficient.
[Edit]
Just tried that workaround is not working in 2.0.2.
Thanks @timscott. The workaround worked as expected:
name: {
type: Sequelize.STRING(50),
allowNull: false,
defaultValue: '',
validate: {
notEmpty: {
msg: 'The name is required.'
}
}
}
Reacted by MaximeMaillet, ilesh21190, okmttdhr, tada, Aleksey Smirnov, Samuel Gaona, Belma Bruner, Lucas Francisco, Henrique Custódia, shahid ahmad, Felipe Caparelli and 2 more
Activity
fixe commentedon Mar 22, 2014
My suggestion:
allowNullshould be independent from the validation component.isNotNullvalidator.isNotNullvalidator as any other one.nunofgs commentedon Apr 1, 2014
+1. @mickhansen what do you think?
mickhansen commentedon Apr 1, 2014
allowNullis currently it's own type of validator, a schema validator - So it doesn't really follow the same logic as regular validators.But yeah we can easily extend the validator in our own codebase (afaik PRs are hardly ever accepted to validator.js): https://github.com/sequelize/sequelize/blob/master/lib/instance-validator.js#L19
mickhansen commentedon Apr 1, 2014
@fixe @nunofgs you should come hang out in IRC too, #sequelizejs @ freenode
olive75 commentedon Jun 12, 2014
+1, nice feature
tiblu commentedon Oct 1, 2014
+1 to add custom message for "allowNull".
bushev commentedon Dec 12, 2014
+1
jackwilsdon commentedon Dec 31, 2014
+1
epsyan commentedon Jan 10, 2015
+1
goodthing commentedon Jan 20, 2015
+1
cithukyaw commentedon Feb 16, 2015
What is the solution for this?
notEmptyornotNulldid not work.or
My sequelize version is 2.0.2.
cithukyaw commentedon Feb 16, 2015
@epsyan Thanks. I have seen that workaround. I expect the Sequelize to be fixed internally, otherwise I would have to use the hook in every schema that is not efficient.
[Edit]
Just tried that workaround is not working in 2.0.2.
43 remaining items
ericsorenson commentedon Nov 2, 2017
👍
DmytroMysak commentedon Nov 6, 2017
+1
brsalviano commentedon Nov 29, 2017
Thanks @timscott. The workaround worked as expected:
tybro0103 commentedon Jan 13, 2018
+1
dydome commentedon May 10, 2018
Is there any update on it?
acodercat commentedon Oct 15, 2018
{
"message": "Warning "notNull" validation has been deprecated in favor of Schema based "allowNull""
}
sushantdhiman commentedon Oct 15, 2018
@acodercat only
5.0.0-beta.9or aboveacodercat commentedon Oct 15, 2018
How should I modify allowNull validate msg now?
sushantdhiman commentedon Oct 15, 2018
@acodercat Not possible in v4, there are some hacks discussed in this thread though
Marcosaurios commentedon Dec 7, 2018
So any workaround to set custom validate error message when it's null? The @timscott solution didn't work for me
jackwilsdon commentedon Jan 31, 2019
@PauloLira this has already been implemented, you need to use
>=5.0.0-beta.9for the deprecated message to go away. See this comment above.xuxuewen commentedon Jul 12, 2019
mafei-dev commentedon Jan 4, 2020
@cjroth

You can use validate with isNull. if value is null, you can throw an error with custom message like bellow. (allowNull must be true)
Then your output will be appear like this .