question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onUpdate not working

See original GitHub issue

onUpdate 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:closed
  • Created 4 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
papbcommented, Aug 1, 2019

@rajat12a I have a weird request - can you please test again using camelCase instead of snake_case for all your fields? I have a feeling this might be related to several weird things happening with underscored fields in sequelize v5.

0reactions
github-actions[bot]commented, Jan 10, 2022

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. 🙂

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found