I am learning how to use sequelize, so far it is a great ORM but I am stuck with the custom validation messages.
I am using the sequelize-cli library to handle migration and I found an issue, custom validation messages don't work if you use the sequelize-cli to create tables, I tried the sequelize.sync method to create the tables and it worked.
Code
This is how I create a field with a custom validation message
Wallet.js
userId: {
type: DataTypes.UUID,
unique: {
name: 'Wallets_userId_unique',
msg: 'This user already have a wallet'
}
},
WalletMigration.js (Not actual migration file name)
userId: {
allowNull: false,
type: Sequelize.UUID,
unique: true,
},
When I tried to create a Wallet with the same userId, I get a Validation error
but I should get This user already have a wallet
.
The message I am getting is the default message provided by the database because I used unique: true
in the migration, If I remove that option the model validation doesn't work.
I want to know what can I do to change this behavior or maybe I am missing something?