So I want to drop a constraint using Knex.js, but I need to check if the constraint is present before I do this. I haven't found a way yet. Anyone have an idea?
Here's my function:
async alterTable_dropConstraint(tableName, constraintDropped) {
return await knex.schema.raw(`ALTER TABLE ${tableName} DROP CONSTRAINT ${constraintDropped}`);
}
Answer (or the code that worked for me): Add 'IF EXISTS'
async alterTable_dropConstraint(tableName, constraintDropped) {
return await knex.schema.raw(`ALTER TABLE ${tableName} DROP CONSTRAINT IF EXISTS ${constraintDropped}`);
}