Search code examples
node.jsknex.js

knex how to auto update column value?


mysql

`modify_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'modify datetime'

javascript

knex.schema.createTable(`record_${today}`,
    function (table) {
        table
            .datetime("modify_at")
            .comment("modify date")
            .notNullable()
            .onUpdate(knex.fn.now());
    }
);

the code run error. it say onUpdate is not a function


Solution

  • For this porpoise, you can use timestamps method http://knexjs.org/#Schema-timestamps