Skip to content
Advertisement

Remove constraints in sequelize migration

I’m adding a unique constraint in a migration via the migrations.changeColumn function.

Adding the constraint works, but since you need to provide a “backwards migration“, removing it the same way does not. It doesn’t give any errors when migrating backwards, but again applying the forward migration results in Possibly unhandled SequelizeDatabaseError: relation "myAttribute_unique_idx" already exists.

(The used database is postgres)

JavaScript

I also tried using removeIndex

JavaScript

But it gives the following error when reverting the migration:

JavaScript

Advertisement

Answer

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

queryInterface.removeConstraint(tableName, constraintName)

Documentation is here.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement