Sometimes, we want to fix "Unknown column ‘*.createdAt’ in ‘field list’" in Sequelize.
In this article, we’ll look at how to fix "Unknown column ‘*.createdAt’ in ‘field list’" in Sequelize.
How to fix "Unknown column ‘*.createdAt’ in ‘field list’" in Sequelize?
To fix "Unknown column ‘*.createdAt’ in ‘field list’" in Sequelize, we should make sure the created_at column is in the database table and the createAt property is in the model.
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 call sequelize.define to define the 'users' model.
In it, we add the createdAt column and set the column type to Sequelize.DATE.
And we map the field to the created_at column in the users table.
Conclusion
To fix "Unknown column ‘*.createdAt’ in ‘field list’" in Sequelize, we should make sure the created_at column is in the database table and the createAt property is in the model.