Ref. https://stackoverflow.com/questions/29652538/sequelize-js-timestamp-not-datetime
Just pass in 'TIMESTAMP' string to your type
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('users', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
created_at: {
type: 'TIMESTAMP',
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
allowNull: false
},
updated_at: {
type: 'TIMESTAMP',
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
allowNull: false
}
});
}
};
OR:
module.exports = (sequelize, type) => {
return sequelize.define('blog', {
blogId: {
type: type.INTEGER,
primaryKey: true,
autoIncrement: true
},
text: type.STRING,
createdAt:{
type: 'TIMESTAMP',
defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
allowNull: false
},
updatedAt:{
type: 'TIMESTAMP',
defaultValue: sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
allowNull: false
}
})
}
'Programming > JavaScript, Node.js' 카테고리의 다른 글
[sequelize] 컬럼 정의 (0) | 2021.07.06 |
---|---|
[Sequelize] Data type of Model in Sequelize (1) | 2021.07.06 |
serverless-dotenv-plugin (0) | 2021.06.30 |
Mac 에서 Homebrew 를 통해 node, npm, yarn 설치하기 (0) | 2021.06.22 |
Making Asynchronous HTTP Requests in JavaScript with Axios (0) | 2021.06.21 |
댓글