Remove constraints in sequelize migration

As of 2017 with Sequelize 4.4.2, we can remove constraints with queryInterface API:

queryInterface.removeConstraint(tableName, constraintName)

Documentation is here.


Sequelize has removeConstraint() method if you want to remove the constraint. So you can have use something like this:

return queryInterface.removeConstraint('users', 'users_userId_key', {})

where users is my Table Name and users_userId_key is index or constraint name which is generally of the form attributename_unique_key if you have unique constraint which you wanna remove(say).


Unfortunately sequelize doesn't have a builtin migration method to remove constraint. That is why before removing key you need to make a raw query.

down: function (migration, DataTypes) {
  migration.sequelize.query(
    'ALTER TABLE Users DROP CONSTRAINT myAttribute_unique_idx;'
  );
  migration.removeIndex('Users', 'myAttribute_unique_idx');

  return;
}