Skip to content

[Sequelize.Op.regexp]: '^[a-zA-Z0-9]{2}\d{10}$' not working with queryInterface.addConstraint sequelize #15436

Discussion options

You must be logged in to vote

Hello, the error message displays that it is necessary to specify the options.fields, so I think that's the problem.
Try to set these fields and I believe this could be an solution. Considering your code make this change:

  async up (queryInterface, Sequelize) {
    await queryInterface.addConstraint('Table', ['column'], {
      type: 'check',
      name: 'checkNumber',
      fields: ['column'], // insert this fields definition
      where: {
        column: {
          [Sequelize.Op.regexp]: '^[a-zA-Z0-9]{2}\d{10}$'
        }
      }
    });
  },

  async down (queryInterface, Sequelize) {
    await queryInterface.removeConstraint('Table', 'checkNumber');
  }
};

As you left only a snippe…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ephys

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet
3 participants
Converted from issue

This discussion was converted from issue #15435 on December 11, 2022 14:29.