node.js – 避免由sequelize自动生成created_at和updated_at

如何定义提供created_at和updated_at而不是生成的模型?

我从某个地方导入数据,这些数据已经包含了我想保留的created_at和updated_at字段的数据,而不是每当对象由sequelize(我们的辅助存储)创建/更新时生成.

我已经尝试了模型定义和选项的所有可能的排列以使其工作,并且仍然使用它自己的时间戳覆盖我的字段:{silent:true}等等…

为了清楚起见,输入数据已经创建了和更新了,我想使用sequelize的bulkCreate()等,这样提供的输入值就会被使用,并作为created_at和updated_at存储在模型上,而不是由sequelize生成.

这是我目前的模型定义:

const Lead = sequelize.define('lead',{
  objectId: {
    type: Sequelize.STRING,field: 'objectId',primaryKey: true,allowNull: false
  },firstName: {
    type: Sequelize.STRING,field: 'first_name'
  },lastName: {
    type: Sequelize.STRING,field: 'last_name'
  },phoneNumber: {
    type: Sequelize.STRING,field: 'phone_number'
  },createdAt: {
    type: Sequelize.DATE,field: 'created_at',},updatedAt: {
    type: Sequelize.DATE,field: 'updated_at'
  }
},{
  freezeTableName: true,// Model tableName will be the same as the model name
  timestamps: false,underscored: true
});

解决方法

选项是

timestamps: false,

时间戳写成完全小写的位置

更新:

从查看bulkCreate()函数代码,it looks that it always updates the timestamps,所以,没有补丁,这是不可能的

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...