I used sequelize-auto
to generate schema, and I tried to use findOne()
and I got 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 is no updatedAt
field in the 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?
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
Create one json file for all model configuration options (flag object as defined here).
When executing command you have to pass -a
or --addtional
option for that where you have to pass json file configuration path.