Last active
December 29, 2021 14:12
-
-
Save markdboyd/2e6b8ff828a8a9d05e85 to your computer and use it in GitHub Desktop.
Drop constraint from Sequelize model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove constraint and index | |
queryInterface.sequelize.query( | |
'ALTER TABLE "project" DROP CONSTRAINT IF EXISTS project_name_key;' | |
).then(function() { | |
return queryInterface.removeIndex('project', 'project_name_key'); | |
}); | |
// Add unique constraint and index | |
queryInterface.addIndex('project', ['name'], { | |
indexName: 'project_name_key', | |
indicesType: 'UNIQUE' | |
}); |
queryInterface.removeConstraint()
doesn't work for me. It throws error, can't find constraint with particular name, even though i have one
above raw query worked for me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
queryInterface.removeConstraint() now exists! http://docs.sequelizejs.com/class/lib/query-interface.js~QueryInterface.html#instance-method-removeConstraint