queryInterface.removeColumn doesn't drop enum type (Postgres)
See original GitHub issueWhat are you doing?
I have the a migration that removes a column with an ENUM
type. Reverting the migration fails because Sequelize didn’t drop the enum type, and reversion fails when it tries to recreate the already-existing type.
Maybe this is intended behavior, but I would think that removeColumn
should always clean up everything that addColumn
or sync
created.
// @flow
import type SequelizeClass, {QueryInterface} from 'sequelize'
const Channels = 'Channels'
module.exports = {
async up(queryInterface: QueryInterface, Sequelize: Class<SequelizeClass>): Promise<void> {
await queryInterface.removeColumn(Channels, 'mode')
},
async down(queryInterface: QueryInterface, Sequelize: Class<SequelizeClass>): Promise<void> {
await queryInterface.addColumn(Channels, 'mode', {
type: Sequelize.ENUM('ANALOG_INPUT', 'DIGITAL_INPUT', 'DIGITAL_OUTPUT', 'DISABLED'),
allowNull: false,
defaultValue: 'DISABLED',
})
},
}
What do you expect to happen?
The down
method succeeds after up
has been performed
What is actually happening?
down
results in the following error:
SequelizeDatabaseError: type "enum_Channels_mode" already exists
Dialect: postgres Dialect version: 6.4.2 Database version: 10 Sequelize version: 4.29.2 Tested with latest release: Yes (If yes, specify that version)
Note : Your issue may be ignored OR closed by maintainers if it’s not tested against latest version OR does not follow issue template.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Sequelize removeColumn method doesn't remove enum types
module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.addColumn('Results', 'mid_term_type', Sequelize.ENUM(['first' ...
Read more >Remove enums in Sequelize / Postgres down migrations
If you are adding a new enum in your migrations, you may want to manually drop the type in your down() migration. This...
Read more >Sequelize removeColumn method doesn't remove enum types ...
Coding example for the question Sequelize removeColumn method doesn't remove enum types-postgresql.
Read more >PostgresQueryInterface - Sequelize
Since postgres has a special case for enums, we should drop the related enum type within the table and attribute. public.
Read more >Dealing with Enum Type in PostgreSQL - DEV Community
Enum type is best solution to describe state data. ... Other than that, PostgreSQL doesn't support changing or deleting specific enum value.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sushantdhiman did you guys assume that Postgres can’t handle that properly? Looks like it can: https://www.postgresql.org/docs/8.2/static/sql-droptype.html
Actually this is a duplicate of long standing issue https://github.com/sequelize/sequelize/issues/2554