Skip to content

ARRAY(ENUM) does not work in Migrations (postgres) #10388

Closed

Description

@MunifTanjim

What are you doing?

migration file: ./project/database/migrations/20190101060000-create-info.js

'use strict'

module.exports = {
  up: (queryInterface, Sequelize) => {
    try {
      return queryInterface.createTable('Infos', {
        InfoId: {
          allowNull: false,
          autoIncrement: true,
          primaryKey: true,
          type: Sequelize.INTEGER
        },
        type: {
          allowNull: false,
          defaultValue: ['personal'],
          type: Sequelize.ARRAY(
            Sequelize.ENUM([
              'current',
              'permanent',
              'home',
              'office',
              'personal'
            ])
          )
        },
        createdAt: {
          allowNull: false,
          type: Sequelize.DATE
        },
        updatedAt: {
          allowNull: false,
          type: Sequelize.DATE
        }
      })
    } catch (err) {
      console.log(err)
      throw err
    }
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('Infos')
  }
}

The main issue is with the Sequelize.ARRAY(Sequelize.ENUM([...])) part.

What do you expect to happen?

The migration to be successful...

What is actually happening?

Sequelize CLI [Node: 8.11.4, CLI: 5.4.0, ORM: 5.0.0-beta.15]

Loaded configuration file "configs/sequelize-cli.config.js".
Using environment "development".
== 20190101060000-create-info: migrating =======
TypeError: Cannot read property 'getTableName' of undefined
    at ARRAY._stringify (./project/node_modules/sequelize/lib/dialects/postgres/data-types.js:573:54)
    at ARRAY.stringify (./project/node_modules/sequelize/lib/data-types.js:33:17)
    at PostgresQueryGenerator.escape (./project/node_modules/sequelize/lib/dialects/abstract/query-generator.js:955:30)
    at PostgresQueryGenerator.attributeToSQL (./project/node_modules/sequelize/lib/dialects/postgres/query-generator.js:502:31)
    at PostgresQueryGenerator.attributesToSQL (./project/node_modules/sequelize/lib/dialects/postgres/query-generator.js:578:45)
    at QueryInterface.createTable (./project/node_modules/sequelize/lib/query-interface.js:233:38)
    at Object.up (./project/database/migrations/20190101060000-create-info.js:6:29)
    at ./project/node_modules/umzug/lib/migration.js:130:33
    at Generator.next (<anonymous>)
    at step (./project/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at ./project/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

ERROR: Cannot read property 'getTableName' of undefined

Dialect: postgres
Dialect version: "pg": "^7.8.0", "pg-hstore": "^2.3.2",
Database version: 11.1
Sequelize version: 5.0.0-beta.15
Tested with latest release: 5.0.0-beta.15

Activity

  1. stale commented on Apr 25, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

  2. MunifTanjim commented on Apr 25, 2019

    @MunifTanjim
    Author

    👋🏼

  3. nhattran998 commented on Aug 5, 2019

    @nhattran998

    Still not working, hope you can fix @papb

    Screen Shot 2019-08-05 at 12 04 01

  4. added
    dependency
    dialect: postgres
    status: awaiting response
    type: bug
    on Aug 5, 2019
  5. papb commented on Aug 5, 2019

    @papb
    Member

    Is this solely an issue with migrations, or something similar can be reproduced without the CLI?

  6. nhattran998 commented on Aug 5, 2019

    @nhattran998

    Is this solely an issue with migrations, or something similar can be reproduced without the CLI?

    It's migrations!

  7. papb commented on Aug 5, 2019

    @papb
    Member

    @jetaimefrc Are you saying that running the queryInterface.createTable() call outside the migrations environment works?

  8. nhattran998 commented on Aug 5, 2019

    @nhattran998

    I do migrate up to migrations table! Yes, I used queryInterface.createTable()

  9. papb commented on Aug 5, 2019

    @papb
    Member

    I discovered that this is not a Migrations issue. I opened a clean new issue to track this: #11285

  10. LWanjiru commented on Sep 21, 2023

    @LWanjiru

    Hope this helps. I was stuck too long trying to figure it out after I got major bugs on a project. Here's the link to how I solved it ==> #11285 (comment)

  11. removed
    status: awaiting response
    on Sep 21, 2023
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

    dependencydialect: postgrestype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions