当我尝试使用Sequelize V4和节点js插入记录时,会发生以下错误:
从字符串
转换日期和/或时间时转换失败
createdAt
和updatedAt
列出现以上错误。
我的代码是
const School = sequelize.define('school_data', {
id:{
type:Sequelize.INTEGER,
primaryKey:true,
autoIncrement:true,
},
osteo_schl_id: Sequelize.STRING,
osteo_schl_name: Sequelize.STRING,
reset_status: Sequelize.STRING,
last_update_dt: Sequelize.DATE,
});
let data = {
osteo_schl_id:schoolId,
osteo_schl_name:schoolName,
reset_status:0
}
School.create(data);
答案 0 :(得分:1)
从文档http://docs.sequelizejs.com/manual/tutorial/models-definition.html#timestamps中,您可以将createdAt和updateAt字段设置为时间戳
id:{
type:Sequelize.INTEGER,
primaryKey:true,
autoIncrement:true,
}
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE,
如果您不需要,只需将timestamps:false
设置为模型防御