我如何定义一个模型,为其提供创建的和更新的,而不是生成的?

我正在从已经有created_atupdated_at个字段的数据的地方导入数据,我希望在sequelize(我们的二级存储)创建/更新对象时保留这些数据,而不是生成这些数据.

我已经try 了所有可能的模型定义和选项的排列,以使其工作,但sequelize仍然会用自己的时间戳覆盖我的字段:{silent: true}等等...

要明确的是,输入数据有createdAt和updatedAt,我想使用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
});

推荐答案

Select 是

timestamps: false,

其中timestampsfully lowercase

Update:

bulkCreate()函数的代码来看,it looks that it always updates the timestamps,没有补丁,现在是不可能的

Postgresql相关问答推荐

到第二天的Postgres计时器

端口5432失败:致命:数据库xxx&不存在.在PostgreSQL数据库中

如何防止 PDO 将问号解释为占位符?

Django 1.8 数组字段追加和扩展

Rails:安装 pg gem 时出错

Postgresql - 在 Big Data 库中使用数组的性能

Docker Compose + Spring Boot + Postgres 连接

PostgreSQL:将时间戳转换为时间 - 或仅从时间戳列中检索时间

Select 中的 PostgreSQL 正则表达式捕获组

django.db.utils.IntegrityError:duplicate key value violates unique constraint "django_content_type_pkey"

如何在 psql 控制台中打印当前工作目录?

Rails:PG :: InsufficientPrivilege:错误:permission denied for relation schema_migrations

如何将主键添加到视图?

在 postgresql 中将 bool 转换为 int

从长时间的postgres转换日期

Entity Framework Core jsonb 列类型

如何在 postgres 查询中排名

由于不支持身份验证类型 10,无法连接到 Postgres DB

Rails 5 db 迁移:如何修复 ActiveRecord::ConcurrentMigrationError

postgresql NOT ILIKE 子句不包含空字符串值