onUpdate not working
See original GitHub issueonUpdate key in model definition for a column doesn’t update the column value when updated
Sequelize Version : 4.41.2 Node Version : 8.15.0 Dialect : mysql
I have a table test
as described below:
+--------------+--------------------------------+------+-----+---------+----------------+
| 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 | |
+--------------+--------------------------------+------+-----+---------+----------------+
and this is its model definition in my code:
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();
}
}
});
When I try to update any column such as is_active the updated_at field value doesn’t change in the database even when onUpdate is mentioned.
Ideally it should update, but it doesn’t.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (9 by maintainers)
Top Results From Across the Web
onupdate not overridinig current datetime value - Stack Overflow
My problem is; I don't want the created_dt/by columns to be updated. I know, in my code I can simply omit them when...
Read more >onupdate not working with postgresql
When I tried updating from sqlalchemy session - things worked for me. SQLalchemy has already implemented the required triggers for auto updation. May...
Read more >Disabling component leads to AppWidgetProvider.onUpdate call
The problem you are encountering is not unique to WorkManager. Anything that enables or disables components in your app will trigger an AppWidgetProvider# ......
Read more >How do I replicate the infinite onUpdate bug that happens with ...
Avoid work in onUpdate by having it only read from a local cache. This cache is written to by a PeriodicWorker that e.g....
Read more >Please Help. onUpdate not updating variables - Garmin Forums
Hi All Just finished my 1st watchface. Everything seem to be working fine except the move bar. The screen redraw works fine
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@rajat12a I have a weird request - can you please test again using
camelCase
instead ofsnake_case
for all your fields? I have a feeling this might be related to several weird things happening with underscored fields in sequelize v5.This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the “stale” label. 🙂