gpt4 book ai didi

node.js - 无法使用 sequelize 更新表

转载 作者:行者123 更新时间:2023-12-03 22:35:46 25 4
gpt4 key购买 nike

我无法使用 sequelize 更新行。似乎它正在跳过查询,因为更新时终端中没有生成日志。其他操作如插入和销毁工作正常。

更新代码

const uuid = require('uuid/v4');

const db = require('../../models');

const TempToken = db.tempTokens;

exports.generateToken = async (req) =>{
'use strict';
const token = uuid();
// let transaction = await db.sequelize.transaction();
try{

console.log(req.userId); /////////// DATA prints in console
console.log(req.device.type); /////////// DATA prints in console

const insert = {
user: req.userId,
device: req.device.type,
};

await TempToken.update({valid: false}, {where:{id: 9 } });

insert['token'] = token;
insert['deviceConfig'] = JSON.stringify(req.device);
await TempToken.create(insert);

return token;
}
catch (e){
return e;
}
};

TempTokens 模型 -
/* jshint indent: 2 */

module.exports = function(sequelize, DataTypes) {
return sequelize.define('tempTokens', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user: {
type: DataTypes.STRING(225),
allowNull: true,
},
token: {
type: DataTypes.STRING(225),
allowNull: false,
},
device: {
type: DataTypes.STRING(225),
allowNull: true,
},
deviceConfig: {
type: DataTypes.TEXT,
allowNull: true,
},
valid: {
type: DataTypes.BOOLEAN,
allowNull: false,
default: true,
},
}, {
tableName: 'tempTokens',
});
};
req.userIdreq.device.type 中的数据有效。而且, id:9 也是有效的并且存在于表中。

终端日志是 -
Executing (default): INSERT INTO `tempTokens` (`id`,`user`,`token`,`device`,`deviceConfig`,`createdAt`,`updatedAt`) VALUES (DEFAULT,?,?,?,?,?,?); 

任何帮助将不胜感激

最佳答案

我认为它应该是 defaultValue 而不是默认值:

valid: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
}

关于node.js - 无法使用 sequelize 更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60906778/

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