onUpdate键在更新后不会更新列值
后续版本:4.41.2 节点版本:8.15.0
我有一个表格test
,如下所述:
+--------------+--------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------------------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| is_active | tinyint(1) | YES | | 1 | |
| created_at | datetime | NO | | NULL | |
| updated_at | datetime | NO | | NULL | |
+--------------+--------------------------------+------+-----+---------+----------------+
这是我的代码中的模型定义:
sequelize.define("test", {
id: {
type: Sequelize.BIGINT,
primaryKey: true,
autoIncrement: true,
},
is_active: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: false
},
created_at: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
allowNull: false,
get: function() {
return new Date(this.getDataValue('created_at')).valueOf();
}
},
updated_at: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
onUpdate : Sequelize.NOW,
allowNull: false,
get: function() {
return new Date(this.getDataValue('updated_at')).valueOf();
}
}
});
当我尝试更新诸如is_active
之类的任何列时,即使提到updated_at
,数据库中的onUpdate
字段值也不会改变。
理想情况下,它应该更新,但不是。