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
Ad