节点JS Sequelize v4在将数据插入SQL Server时生成错误

时间:2017-11-30 05:46:18

标签: sql-server node.js sequelize.js

当我尝试使用Sequelize V4和节点js插入记录时,会发生以下错误:

  

从字符串

转换日期和/或时间时转换失败

createdAtupdatedAt列出现以上错误。

我的代码是

  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);

1 个答案:

答案 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设置为模型防御