Omar Martin
asked on
"No rows affected" when trying to Update Mysql table.
I am updating records using sequelize. I am testing the backend with postman. The code seems to work as there is no error however when testing it in postman, no rows are affected (updated). I have used both put and patch methods, however, I received the same results. Perhaps, there is an error in the code that I am missing.
Here is the code:
router.put('/editstation/: id', (req, res) => {
let newStation = req.body.station;
let newAddress = req.body.address;
let newMonthlycstoresales = req.body.monthlycstoresale s;
let newOperator = req.body.operator;
let newTopsku = req.body.topsku;
let values = {Station: newStation, Address: newAddress, monthlycstoresales: newMonthlycstoresales, Operator: newOperator, topsku:newTopsku};
let selector = {
where: {id: req.params.id}
}
Store.update(values, selector)
.then((updatedPost)=>{
console.log(updatedPost);
res.json({
"message": updatedPost
})
})
.catch(err => {
res.json({
"message": err
})
})
});
Here is the json test in postman
{
"ID": 6,
"Station": "Rargain jiack",
"Operator": "Dilly"
}
Here are the results:
{
"message": [
0
]
}
Here is the code:
router.put('/editstation/:
let newStation = req.body.station;
let newAddress = req.body.address;
let newMonthlycstoresales = req.body.monthlycstoresale
let newOperator = req.body.operator;
let newTopsku = req.body.topsku;
let values = {Station: newStation, Address: newAddress, monthlycstoresales: newMonthlycstoresales, Operator: newOperator, topsku:newTopsku};
let selector = {
where: {id: req.params.id}
}
Store.update(values, selector)
.then((updatedPost)=>{
console.log(updatedPost);
res.json({
"message": updatedPost
})
})
.catch(err => {
res.json({
"message": err
})
})
});
Here is the json test in postman
{
"ID": 6,
"Station": "Rargain jiack",
"Operator": "Dilly"
}
Here are the results:
{
"message": [
0
]
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome.
ASKER