避免由sequelize自动生成created_at和updated_at

Tyl*_*ock 6 postgresql node.js sequelize.js

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

我正在从已经拥有数据的某个地方导入数据created_atupdated_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
});
Run Code Online (Sandbox Code Playgroud)

Tud*_*tin 21

选项是

timestamps: false,
Run Code Online (Sandbox Code Playgroud)

在哪里timestamps完全小写

更新:

通过查看bulkCreate()函数的代码,它看起来总是更新时间戳,因此,如果没有补丁,这现在是不可能的