disable updatedAt (update date) field in sequelize.js

yozawiratama picture yozawiratama · Sep 20, 2016 · Viewed 27.8k times · Source

i used sequelize-auto to generate schema, and i try to using findOne() and i get this error :

Unhandled rejection SequelizeDatabaseError: Invalid column name 'updatedAt'.

in my database table there is no field updatedAt

for example my table name is Users my code is Users.findOne(), and there are no updatedAt field in users table.

db.users= sequelize.import(__dirname + "/models/users");
app.get('/users', function (req, res) {

  db.user.findOne().then(function (project) {
    res.json(project);
  })

});

how to solve it?

Answer

Haresh Vidja picture Haresh Vidja · Sep 20, 2016

Refer to the documentation for configuration of Model in Sequelize

In model object of your table should look like this.

var user = sequelize.define('user', { /* bla */ }, {

  // don't add the timestamp attributes (updatedAt, createdAt)
  timestamps: false,

  // If don't want createdAt
  createdAt: false,

  // If don't want updatedAt
  updatedAt: false,

  // your other configuration here

});

Check Usage of sequelize-auto-generation module

  1. Create one json file for all model configuration options (flag object as defined here).

  2. When executing command you have to pass -a or --addtional option for that where you have to pass json file configuration path.