Skip to content
Advertisement

Sequelize: Cannot set a new unique constraint message

I am trying to setup a validation message for unique constraint violation for the fields username and email. However, whenever an already taken username is entered, it shows the message defined for the email property, but shows the input for the username property and also says that this input is for the username property. How would I fix this? Here is my code:

JavaScript

This is the output I get from input:

JavaScript

So as you can see, it says it is the username that is not unique, but uses the message defined for the email property.

Advertisement

Answer

This is not possible because it is a schema-validator, and not a general validator that falls inside the validate: { } object. The only work around is to include defaultValue: '' and then have a notNull object in the validate object. Otherwise, just removing allowNull disables most validate: {} checks.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement