Categories
JavaScript Answers

How to fix Unknown column ‘*.createdAt’ in ‘field list’ error with Node.js Sequelize?

Spread the love

To fix Unknown column ‘*.createdAt’ in ‘field list’ error with Node.js Sequelize, we add a model with the createdAt field.

For instance, we write

const users = sequelize.define("users", {
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true,
  },
  createdAt: {
    field: "created_at",
    type: Sequelize.DATE,
  },
  updatedAt: {
    field: "updated_at",
    type: Sequelize.DATE,
  },
  //...
});

to add the createdAt field to the users model and map it toi the created_at date field.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *