Mul*_*yan 3 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: true,autoIncrement: true,
},
person_name: {type: DataTypes.STRING(255),allowNull: false},
created: {type: DataTypes.DATE,allowNull: true},
},
{
tableName: 'my_table',
timestamps: false,
createdAt: 'created',
},
);
Run Code Online (Sandbox Code Playgroud)
是否可以在模型本身中解决此问题而不对查询进行任何更改?
根据Init上的文档,您需要打开时间戳功能,但将模型配置为不使用updatedAt.
这是示例代码中选项对象的编辑版本,它应该为您提供所需的内容:
{
tableName: 'my_table',
updatedAt: false,
}
Run Code Online (Sandbox Code Playgroud)
注意:文档说“时间戳必须为真”,这可能表明为什么它没有按照您提供的示例中的方式工作。
干杯!
| 归档时间: |
|
| 查看次数: |
1789 次 |
| 最近记录: |