I am doing a REST tutorial with Knex.js(0.19.0
) and PostgreSQL(11-alpine
, pg@7.11.0
), and I notice that the updatedAt
column does not work when I make PUT
request and update the data.
Currently this is my users
table:
// users_migration.js
exports.up = function(knex) {
return knex.schema.createTable('users', function(table) {
table
.increments('id')
.primary()
.unsigned();
table.string('firstName');
table
.string('lastName')
.index()
.notNullable();
table
.string('email')
.unique()
.index()
.notNullable();
table.string('password').notNullable();
table.string('role').defaultTo('STAFF');
table.boolean('isActive').defaultTo(false);
table.timestamp('createdAt').defaultTo(knex.fn.now());
table.timestamp('updatedAt').defaultTo(knex.fn.now());
});
};
I have tried this:
table.timestamp('createdAt').defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table
.timestamp('updatedAt')
.defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
But it doesn't work either.
How do I make it work? Please help.