Vikas
Vikas

Reputation: 985

Unable to execute the raw query in Sequelize migrations

I am trying to update my database using Sequelize migrations so I have tried to write a Sequelize migrations like this

'use strict';
module.exports = {
  up: (queryInterface, Sequelize, migration) => {
    queryInterface.addColumn('coaching_class_entries', 'bill_cycle', {
      type: Sequelize.INTEGER(4),
      allowNull: false,
      defaultValue: '0',
      field: 'bill_cycle',
      after: 'fees'
    })
      .then(() => queryInterface.addColumn('coaching_classes', 'bill_plans', {
        type: Sequelize.JSON,
        allowNull: false,
        defaultValue: 'NULL',
        field: 'bill_plans',
        after: 'bill_cycle'
      }))
      .then(() =>
        migration.migrator.Sequelize.query('UPDATE coaching_classes  SET bill_plans = JSON_ARRAY(JSON_OBJECT("cycle", bill_cycle, "fee", fees));'));

  },

  down: (queryInterface, Sequelize) => {
    let migrations = [];

    migrations.push(queryInterface.removeColumn('coaching_class_entries', 'bill_cycle'))
    migrations.push(queryInterface.removeColumn('coaching_classes', 'bill_plans'))
    return Promise.all(migrations);

  }
};

But it is always giving me error in raw query line

Cannot read property 'Sequelize' of undefined

What is the correct syntax for this?

Upvotes: 16

Views: 10781

Answers (1)

Vikas
Vikas

Reputation: 985

I found it myself only we have to use simple queryInterface.sequelize.query

Upvotes: 49

Related Questions