Home > OS >  Sequelize unique custom message
Sequelize unique custom message

Time:02-11

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'),
        },
      },
    },

CodePudding user response:

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.

  • Related