question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

queryInterface.changeColumn(...) doesn't seem to work for changing ENUM set.

See original GitHub issue

What 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:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
SvemirskiHodcommented, Sep 10, 2018

@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)

1reaction
sushantdhimancommented, Jan 20, 2018

You are missing return in your migrations?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found