gpt4 book ai didi

mysql - 不使用 sequelize 模型存储 updatedAt

转载 作者:行者123 更新时间:2023-11-29 01:26:30 25 4
gpt4 key购买 nike

当我将模型存储在我的 MySQL 数据库中时,它们是不可变的。结果,我可以看到我的表中需要 createdAt 列,但我不需要多余的 updatedAt 列。我可以配置 sequelize 不存储 updatedAt 时间然后我可以从我的表中删除该列吗?

最佳答案

查看有关您的情况的文档

If you want sequelize to handle timestamps, but only want some of them, or want your timestamps to be called something else, you can override each column individually:

const Foo = sequelize.define('foo',  { /* bla */ }, {
// don't forget to enable timestamps!
timestamps: true,

// I don't want createdAt
createdAt: false,

// I want updatedAt to actually be called updateTimestamp
updatedAt: 'updateTimestamp',

// And deletedAt to be called destroyTime (remember to enable paranoid for this to work)
deletedAt: 'destroyTime',
paranoid: true
})

因此在上面的示例中,只需将 timestamps 设置为 true 然后将 createdAt 设置为 false

关于mysql - 不使用 sequelize 模型存储 updatedAt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45248189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com