gpt4 book ai didi

reactjs - SequelizeDatabaseError 数据在第 4 行的列位置被截断

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

我在发送如下更新请求时收到 SequelizeDatabaseError Data truncated for column 'position' at row 4:有关如何修复数据库错误的任何建议?

执行(默认):UPDATE user SET photo =?, name =?, email =?, phonenumber =?, position =?, password =?, updatedAt =?哪里 email = ?
SequelizeDatabaseError:第 4 行“位置”列的数据被截断
在 Query.formatError (C:\Project\soccerpep\node_modules\sequelize\lib\dialects\mysql\query.js:244:16)
在 Execute.handler [as onResult] (C:\Project\soccerpep\node_modules\sequelize\lib\dialects\mysql\query.js:51:23)

module.exports = function(sequelize, DataTypes) {
return sequelize.define('user', {
name: {
type: DataTypes.STRING(30),
allowNull: false
},
email: {
type: DataTypes.STRING(100),
allowNull: false

},
phonenumber: {
type: DataTypes.STRING(50),

},
id: {
type: DataTypes.INTEGER(10).UNSIGNED,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
password: {
type: DataTypes.STRING(50),
allowNull: false
},
privilege: {
type: DataTypes.ENUM('PLAYER','ADMIN'),

},
photo: {
type: DataTypes.STRING(30),

},
position: {
type: DataTypes.ENUM('FORWARD','MID-FIELD','DEFENDER','GK'),

}
}, {
tableName: 'user'
});
};
server.js
const UserModel = userSchema(sequelize, DataTypes);

app.put('/service/profile', async (req, res, next) => {

try {
const userEmail = req.query.email;
var selector = {
where: { email: userEmail }
};
const updatePlayer = await UserModel.update(req.body, selector);
console.log("Server side update method log:" + updatePlayer);
res.status(200).json({ success: true });
} catch (err) {
return next(err);
}
});

最佳答案

我认为问题在于 ENUM,您只能将其与 Postgres 一起使用,而不能与 mysql 一起使用,( Ref )

position: {
type: DataTypes.ENUM('FORWARD','MID-FIELD','DEFENDER','GK'),
}

将其更改为简单的 string 类型并再次检查,
position: {
type: DataTypes.STRING(30)
}

NOTE : You might need to create table again or update the field manually after changing this in model else you will still get the error

关于reactjs - SequelizeDatabaseError 数据在第 4 行的列位置被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62257097/

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