这是使用 express + mysql 的 node js 项目,我在其中使用 ORM Sequelize。
尝试运行 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');
}
};
最佳答案
问题出在 NUMBER 数据类型上。在 Sequelize 的 DataTypes 列表中找不到哪个 ( https://sequelize.org/master/manual/model-basics.html#data-types )
更改以下内容:
salary: {
type: Sequelize.NUMBER
}
到:
salary: {
type: Sequelize.DECIMAL(10, 2)
}
还要记得更新模型相关的数据类型。
关于javascript - Sequelize迁移错误: Cannot read property 'length' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53291677/