我在这里真是死路一条。
我有一个带有Sequelize的NodeJS Express中内置的API。造成麻烦的方法是这样的:
create(req, res){
agentGame.create({
Agent: req.body.Agent,
Game: req.body.Game,
})
.then(agentGame => res.status(201).send(agentGame))
.catch(error => res.status(400).send(error));
},
每当我向其发送任何数据时,它都会毫无故障地说Agent和Game均为Null。
这是请求正文:{“ Agent”:3,“ Game”:1}
这是模型:
module.exports = function(sequelize, DataTypes) {
return sequelize.define('AgentsGames', {
ID: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
Agent: {
type: DataTypes.INTEGER(11),
allowNull: false
},
Game: {
type: DataTypes.INTEGER(11),
allowNull: false
},
StarterSent: {
type: DataTypes.DATEONLY,
allowNull: true
},
StarterPainted: {
type: DataTypes.DATEONLY,
allowNull: true
},
}, {
tableName: 'AgentsGames'
});
};
我找不到任何理由一直说主体值是Null。我可以将值手动输入到数据库中,如果我将模型设置为允许Null值,它将创建具有null值的条目。
有帮助吗?
答案 0 :(得分:0)
此问题现已修复。
删除了Node_Modules,使用npm install重新安装并重新启动了该应用程序,它再次开始工作,因此,可以认为是Express.Json中的一个故障。