0

I am using sequelize for building and migrating models to postgres. I am trying to add my attributes in an array of objects like this:

approvals: [ { id: { type: Sequelize.INTEGER }, isApproved: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true, }, approvedById: { type: Sequelize.INTEGER, }, }, ],

and it's returning this error

ERROR: syntax error at or near "["

Full createTable() call:

await queryInterface.createTable("leaves", {
          id: {
            type: Sequelize.INTEGER,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
          },
          emp_id: {
            type: Sequelize.INTEGER,
          },
          from: {
            type: Sequelize.DATE,
            allowNull: false,
          },
          to: {
            type: Sequelize.DATE,
            allowNull: false,
          },
          desc: { type: Sequelize.TEXT },
          approvals: [
            {
              id: { type: Sequelize.INTEGER },
              isApproved: {
                type: Sequelize.BOOLEAN,
                allowNull: false,
                defaultValue: true,
              },
              approvedById: {
                type: Sequelize.INTEGER,
              },
            },
          ],
          createdAt: Sequelize.DATE,
          updatedAt: Sequelize.DATE,
        });
    
buddemat
  • 4,552
  • 14
  • 29
  • 49
  • 2
    Welcome to SO. Please format your question properly and add some explanatory text. In the current state, it is completely unclear what you need help with. – buddemat Nov 24 '20 at 13:09
  • sir am using sequelize for building and migrating models to the postgres, at that am trying to add my attributes an array of objects like this approvals: [ { id: { type: Sequelize.INTEGER }, isApproved: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true, }, approvedById: { type: Sequelize.INTEGER, }, }, ], and its returning this error ERROR: syntax error at or near "[" – abdirahman buryar Nov 25 '20 at 02:50
  • Try creating your attributes as an object instead of an array, cmp. `createTable` function documentation (https://sequelize.org/master/class/lib/dialects/abstract/query-interface.js~QueryInterface.html#instance-method-createTable). There should not be any brackets (`[`) in there, see also https://stackoverflow.com/questions/5129544/javascript-arrays-braces-vs-brackets – buddemat Nov 30 '20 at 16:10

0 Answers0