When defining models, Sequelize default behavior is to create createdAt and updateAt timestamp fields, but this is not happening while using migrations. I've tried with and without option timestamp: true, but it doesn't create the fields and no error is thrown. A migration example:
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('users', {
name: {
type: Sequelize.STRING,
allowNull: false
},
email: {
type: Sequelize.STRING,
allowNull: false,
primaryKey: true
},
password: {
type: Sequelize.STRING,
allowNull: false
},
roles: {
type: Sequelize.ARRAY(Sequelize.STRING)
}
}, {
timestamps: true
});
},
down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('users');
}
};
Dialect: postgres
Database version: 9.4
Sequelize version: 3.23.4
createTable doesn't ( and shouldn't ) add any fields auto magically.
When sync method run it take care of timestamps attribute and create them for you. But you will have to define all fields when using createTable. Sequelize will not magically add any surprise columns.
Also there is no support for options.timestamps in createTable, Its used to set charset, engine etc
Most helpful comment
createTabledoesn't ( and shouldn't ) add any fields auto magically.When
syncmethod run it take care oftimestampsattribute and create them for you. But you will have to define all fields when usingcreateTable. Sequelize will not magically add any surprise columns.Also there is no support for
options.timestampsincreateTable, Its used to setcharset,engineetc