I've been going through this tutorial and the github repository for creating an express/passport/sequelize authorization using a Postgres database. I know what the issue is, I just need help with a solution.
After having everything in place and creating database, I try to login, but I keep getting the error:
"SequelizeDatabaseError" column "createdAt" does not exist".
There appears to be a bug where Sequelize 3.X.X is not able to read createdAt
and the database I set up will automatically lowercase all tables created.
I believe there is a way to fix the createdAt
requirement to be lowercase, but I can't seem to locate it at all. Has anyone else encountered a similar issue?
if you dont want to take the time you should do:
var config = {
"define": {
whatever: req.body.whatever,
...
} ,{
timestamps: false
}
}
if you can't seem to fix the column name to createdAt
then you can just add an extra field to the sequelize config
var config = {
"define": {
"createdAt": "createdat",
"updatedAt": "updatedat"
} /*don't forget to add host, port, dialect, etc.*/
}
var sequelize = new Sequelize(database, username, password, config);
I had the same issue and I fixed it by adding this to the sequelize config
const sequelize = new Sequelize({
....
define: {
underscored: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
}
});
create created-at, updated-at in migration like this :
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
updated_at: {
allowNull: false,
type: Sequelize.DATE,
},
then make sure to add field name mapping in your models files :
createdAt: {
type: DataTypes.DATE,
field: 'created_at'
},
updatedAt: {
type: DataTypes.DATE,
field: 'updated_at'
},
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