`queryInterface.removeColumn` attempts to remove non-existing constraints
See original GitHub issueThis case worries me because in some cases, Sequelize takes information from another database than from the one it is configured to use (located on the same server).
What you are doing?
I’m implementing this simple migration.
module.exports = {
up: function (queryInterface) {
queryInterface.removeColumn('myModel', 'colName');
}
}
This column has no constraint (no index, no foreign key constraint), thus should be deleted with a simple ALTER TABLE … DROP … query to the DB.
However, on my MariaDB server, another database exists with the same table, but with constraints set on this column.
What do you expect to happen?
The column should be properly removed from the table.
What is actually happening?
An error is thrown:
Unhandled rejection SequelizeDatabaseError: ER_CANT_DROP_FIELD_OR_KEY: Can't DROP 'foreign_key_constraint_name'; check that column/key exists
This is because Sequelize queries the INFORMATION_SCHEMA of the whole MariaDB server to find constraints on the column before removing them if they exist.
The query to INFORMATION_SCHEMA generated by Sequelize should have a condition on the DB name (namely on the CONSTRAINT_SCHEMA column) !
Right now, it finds constraints on other databases, and tries to removes them from the current one !
Dialect: mariadb Sequelize version: 3.24.1
Issue Analytics
- State:
- Created 7 years ago
- Reactions:16
- Comments:8 (4 by maintainers)
+1 faced with the same problem
@papb It seems this bug is still here when using a schema in Postgres