简体   繁体   中英

Sequelize migration error: Cannot read property 'length' of undefined

This is the tutorial I followed: https://medium.com/@prajramesh93/getting-started-with-node-express-and-mysql-using-sequelize-ed1225afc3e0

This is node js project using express + mysql where I use and ORM Sequelize.

I get this error when trying to run sequelize db:migrate

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Employees', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      name: {
        type: Sequelize.STRING
      },
      designation: {
        type: Sequelize.STRING
      },
      salary: {
        type: Sequelize.NUMBER
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      companyId: {
        type: Sequelize.NUMBER,
        onDelete: 'CASCADE',
        references: {
          model: 'Companies',
          key: 'id',
          as: 'companyId',
        }
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Employees');
  }
};

Problem was relying on NUMBER DataType. Which was not found in the list of DataTypes of Sequelize ( https://sequelize.org/master/manual/model-basics.html#data-types )

Change the following:

salary: {
            type: Sequelize.NUMBER
        }

to:

salary: {
            type: Sequelize.DECIMAL(10, 2)
        }

Also remember to update DataType the model related.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM