Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable updatedAt (update date) field in sequelize.js

Tags:

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?

like image 961
yozawiratama Avatar asked Sep 20 '16 07:09

yozawiratama


People also ask

How do you prevent createdAt and updatedAt in Sequelize?

With timestamps: false , the generated model will omit the createdAt and updatedAt attributes. You can also opt to include only the timestamp attribute you need as shown below: const User = sequelize. define( "User", { firstName: Sequelize.

Is there a simple way to make Sequelize return It's date/time fields in a particular format?

Is there a simple way to make Sequelize return It's date/time fields in a particular format? You can, use the Sequelize fn method. From the API Reference, the fn function will help create an object representing a SQL function in your query.

What is required false in Sequelize?

sequelize fails to load a model if a nested include has a where clause that returns no models.. to ensure it doesnt fail completely, you can set a required: false clause along with the where clause.. this makes sequelize return a blank array instead of failing the load completely.. Save this answer.


1 Answers

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.

like image 94
Haresh Vidja Avatar answered Sep 29 '22 07:09

Haresh Vidja