如何定义提供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,所以,没有补丁,这是不可能的