Timestamps

By default, Sequelize will add the attributes createdAt and updatedAt to your model so you will be able to know when the database entry went into the db and when it was updated last.

Note that if you are using Sequelize migrations you will need to add the createdAt and updatedAt fields to your migration definition:

  1. module.exports = {
  2. up(queryInterface, Sequelize) {
  3. return queryInterface.createTable('my-table', {
  4. id: {
  5. type: Sequelize.INTEGER,
  6. primaryKey: true,
  7. autoIncrement: true,
  8. },
  9. // Timestamps
  10. createdAt: Sequelize.DATE,
  11. updatedAt: Sequelize.DATE,
  12. })
  13. },
  14. down(queryInterface, Sequelize) {
  15. return queryInterface.dropTable('my-table');
  16. },
  17. }

If you do not want timestamps on your models, only want some timestamps, or you are working with an existing database where the columns are named something else, jump straight on to configuration to see how to do that.