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?
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? 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With