我正在使用sequelize 5.6.1从Nodejs 10.15服务器上的verifLog
模型中检索记录:
hit = await VerifLog.findOne({where : {vcode: vcode_received,
cell: cell,
cell_country_code: cell_country_code,
device_id: device_id,
redeemed: false}});
但是createdAt
在hit
中为空,即使表中有createdAt的有效值(2019-04-27 23:10:15.827-07
):
hit is : veriflog {
dataValues:
{ id: 31,
cell: '6303623200',
cell_country_code: '1',
vcode: '90282',
device_id: '8c9c25711c7d0262',
redeemed: false,
user_id: '20',
createdAt: 2019-04-28T06:10:15.827Z },
_previousDataValues:
{ id: 31,
cell: '6303623200',
cell_country_code: '1',
vcode: '90282',
device_id: '8c9c25711c7d0262',
redeemed: false,
user_id: '20',
createdAt: 2019-04-28T06:10:15.827Z },
_changed: {},
.......
这是VerifLog模型:
const VerifLog = db.define('veriflog', {
/* id: {type: Sql.INTEGER,
primaryKey:true,
autoIncrement: true,
min: 1}, */
cell: Sql.STRING,
cell_country_code: Sql.STRING,
vcode: Sql.STRING,
device_id: Sql.STRING,
redeemed: {
type: Sql.BOOLEAN,
default: false
},
user_id: Sql.INTEGER,
}, {
timestamps: true,
updatedAt: false,
indexes: [
{
fields: ['cell_country_code', 'cell'],
},
{
fields: ["device_id"],
},
{
fields: ["redeemed"],
},
{
fields: ['user_id'],
},
],
});
我不知道为什么createdAt
仅返回空。
答案 0 :(得分:1)
尝试在模型中定义createdAt
和updatedAt
。我的猜测是,尽管记录中有可用数据,但是由于您尚未在模型属性中定义字段,因此sequelize不会为createdAt
和updatedAt
定义吸气剂。