Sequelize迁移错误:无法读取未定义的属性“ length”

时间:2018-11-14 00:58:58

标签: javascript mysql node.js express sequelize.js

这是我遵循的教程:https://medium.com/@prajramesh93/getting-started-with-node-express-and-mysql-using-sequelize-ed1225afc3e0

这是我使用Express + mysql和ORM Sequelize的节点js项目。

尝试运行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');
  }
};

1 个答案:

答案 0 :(得分:8)

问题取决于NUMBER数据类型。在Sequelize(http://docs.sequelizejs.com/manual/tutorial/models-definition.html#data-types)的数据类型列表中找不到哪个

更改以下内容:

salary: {
            type: Sequelize.NUMBER
        }

收件人:

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

还记得更新与模型相关的DataType。