Mysql 在Sequelize中仅启用createdAt时间戳并忽略updatedAt时间戳
我试图在表中创建一些只填充createdAt列的记录。我希望updatedAt列不存在,但在创建模型时,它会自动生成createdAt和updatedAt时间戳 我试图使用Mysql 在Sequelize中仅启用createdAt时间戳并忽略updatedAt时间戳,mysql,node.js,express,sequelize.js,Mysql,Node.js,Express,Sequelize.js,我试图在表中创建一些只填充createdAt列的记录。我希望updatedAt列不存在,但在创建模型时,它会自动生成createdAt和updatedAt时间戳 我试图使用timestamps:false,但createdAt列包含空值 const MyTable = sequelize.define( 'my_table', { id: { type: DataTypes.INTEGER(11),allowNull: false, primaryKey:
timestamps:false
,但createdAt列包含空值
const MyTable = sequelize.define(
'my_table',
{
id: {
type: DataTypes.INTEGER(11),allowNull: false,
primaryKey: true,autoIncrement: true,
},
person_name: {type: DataTypes.STRING(255),allowNull: false},
created: {type: DataTypes.DATE,allowNull: true},
},
{
tableName: 'my_table',
timestamps: false,
createdAt: 'created',
},
);
是否可以在不更改查询的情况下在模型本身中修复此问题 根据,您希望保持时间戳功能处于打开状态,但将您的模型配置为不使用updatedAt
下面是示例代码中options对象的编辑版本,它应该提供您所要查找的内容:
{
tableName: 'my_table',
updatedAt: false,
}
注意:文档中说“时间戳必须是真的”,这可能说明了为什么它没有像您提供的示例中那样工作
干杯