queryInterface.changeColumn(...) doesn't seem to work for changing ENUM set.
See original GitHub issueWhat are you doing?
I’m doing the following in my migration file:
up: (queryInterface, Sequelize) => {
queryInterface.changeColumn('data', 'sourceType', {
type: Sequelize.ENUM(
'FILE',
'API',
),
defaultValue: 'API'},
)
},
down: (queryInterface, Sequelize) => {
queryInterface.changeColumn('data', 'sourceType', {
type: Sequelize.ENUM(
'FILE',
'API',
),
defaultValue: 'API'},
)
}
};
What do you expect to happen?
Migrate the table and change existing sourceType
column to be the new ENUM type.
What is actually happening?
I’m seeing the following error when running the migration:
Unhandled rejection SequelizeDatabaseError: type "enum_data_sourceType" already exists
Dialect: postgres Dialect version: (PostgreSQL) 10.0 Database version: XXX HUH? Sequelize version: Sequelize CLI [Node: 8.7.0, CLI: 3.0.0, ORM: 4.31.2] Tested with latest release: No (If yes, specify that version)
WARNING: This version of Sequelize CLI is not fully compatible with Sequelize v4. https://github.com/sequelize/cli#sequelize-support
3.0.0
… Just seeing this. Gonna post anyway to confirm (sorry) but does it sound like I need to update? Or is what I’m doing actually not supported?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Sequelize: Change column type to ENUM - node.js
Postgres doesn't know that the string data in oldcolumn can fit into the enum values - try casting it
Read more >Postgres: Enum type fields | Hasura GraphQL Docs
Use enums in Hasura with Postgres. ... Postgres: Enum type fields. Introduction. Enum type fields are restricted to a fixed set of allowed...
Read more >Updating Enum Values in PostgreSQL - The Safe and Easy Way
Lets say we want to remove the waiting status and set all waiting jobs to running . # remove references to the deprecated...
Read more >Sequelize migration with enum values - michael le
I was having a hard time changing a database column to add an enum value. It turns out that Sequelize and Postgres doesn't...
Read more >Persisting Enums in JPA - Baeldung
It just doesn't feel right to have two attributes representing a single enum in the entity. Additionally, if we use this type of...
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
@ashok-sc thank you for the suggestion. I might end up doing the same.
Btw I’ve discovered that calling
Sequelize.sync()
once you have defined the new ENUM values in the model does the updates correctly. Not the best solution, but still a possibility.It also seems that someone has written a package that handles the enum updates: https://www.npmjs.com/package/sequelize-replace-enum-postgres. I think I would rather migrate away from enums like you mentioned (and perhaps handle the value restrictions inside the model)
You are missing
return
in your migrations?