这是我使用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');
}
};
答案 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。