Skip to content

Issue with setting defaultValue on enum after 3.5.0 #4196

Closed

Description

@shiboe

We have a migration that creates a table with an enum column. After 3.5.0, the migration fails with the following error:

== 20150608103440-create-timeline-invite: migrating =======
Unhandled rejection SequelizeValidationError: "pending" is not a valid choice in []
    at ENUM.validate (./node_modules/sequelize/lib/data-types.js:692:11)
    at Object.QueryGenerator.escape (./node_modules/sequelize/lib/dialects/postgres/query-generator.js:894:20)
    at Object.QueryGenerator.attributeToSQL (./node_modules/sequelize/lib/dialects/postgres/query-generator.js:504:40)
    at Object.QueryGenerator.attributesToSQL (./node_modules/sequelize/lib/dialects/postgres/query-generator.js:576:45)
    at ./node_modules/sequelize/lib/query-interface.js:165:40
    at tryCatcher (./node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (./node_modules/bluebird/js/main/promise.js:503:31)
    at Promise._settlePromiseAt (./node_modules/bluebird/js/main/promise.js:577:18)
    at Promise._settlePromises (./node_modules/bluebird/js/main/promise.js:693:14)
    at Async._drainQueue (./node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (./node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (./node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:358:17)

Setting Sequelize to v3.4.1 runs fine with no errors.

For reference, the relevant bits of the model:

...
    },
    status: {
      type: DataTypes.ENUM('pending', 'accepted', 'cancelled', 'rejected'),
      defaultValue: 'pending'
    },
...

and migration:

...
      },
      status: {
        type: Sequelize.ENUM,
        values: ['pending', 'accepted', 'cancelled', 'rejected'],
        defaultValue: 'pending'
      },
...

Activity

  1. janmeier commented on Jul 28, 2015

    @janmeier
    Member

    Should be fixed by #4186 - normalizeAttribute has been refactored to make sure type.values will always be set

  2. janmeier commented on Feb 21, 2016

    @janmeier
    Member

    Works on latest master - tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions