Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MunifTanjim opened this issue Jan 25, 2019 · 9 comments
Closed

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

MunifTanjim opened this issue Jan 25, 2019 · 9 comments
Labels
dependency For issues and PRs. Things that are related to one or more dependencies. dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). type: bug

Comments

@MunifTanjim
Copy link

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

@stale
Copy link

stale bot commented Apr 25, 2019

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 🙂

@stale stale bot added the stale label Apr 25, 2019
@MunifTanjim
Copy link
Author

👋🏼

@stale stale bot removed the stale label Apr 25, 2019
@harrytran998
Copy link

Still not working, hope you can fix @papb

Screen Shot 2019-08-05 at 12 04 01

@papb papb added dependency For issues and PRs. Things that are related to one or more dependencies. dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action type: bug labels Aug 5, 2019
@papb
Copy link
Member

papb commented Aug 5, 2019

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

@harrytran998
Copy link

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

It's migrations!

@papb
Copy link
Member

papb commented Aug 5, 2019

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

@harrytran998
Copy link

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

@papb
Copy link
Member

papb commented Aug 5, 2019

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

@papb papb closed this as completed Aug 5, 2019
@LWanjiru
Copy link

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)

@github-actions github-actions bot removed the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency For issues and PRs. Things that are related to one or more dependencies. dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). type: bug
Projects
None yet
Development

No branches or pull requests

4 participants