Node.js err TypeError:values.map不是函数

Node.js err TypeError:values.map不是函数,node.js,postgresql,sequelize.js,Node.js,Postgresql,Sequelize.js,我正在尝试通过id查找帖子并添加评论 我正在使用postgreSQL 这是我的模型 const Sequelize = require('sequelize') const db = require('../../config/database') const Posts =db.define("Topics",{ id: { type: Sequelize.INTEGER, primaryKey: true,

我正在尝试通过id查找帖子并添加评论

我正在使用postgreSQL

这是我的模型

   const Sequelize = require('sequelize')
const db = require('../../config/database')

const Posts =db.define("Topics",{
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    title : {
        type : Sequelize.STRING,
    },
    description : {
        type: Sequelize.STRING
    },
    username : {
        type: Sequelize.STRING
    },
    comment : {
        type:Sequelize.ARRAY(Sequelize.STRING),
        defaultValue : [],
        allowNull: false
    }

})
module.exports = Posts;
这是我的nodeJS请求

    app.put('/addComment/:id', (req, res) => {
    Posts.update({
            comment: req.body.comment
        },
        {
            where: {
                id: req.params.id
            }
        }).then((post) => {
        res.send(post)
    }).catch((err) => {
        console.log("err", err);
    });
})
我正在使用postman测试我的服务器,但每当我尝试将更新的数据发送到数据库时,总是会出现以下错误
err-TypeError:values.map不是一个函数

有没有关于如何解决这个问题的建议? 在我的DB中,注释数组的数据类型也是
text[]

我还尝试将
update
更改为
create
,但没有结果

我通过将:req.body.comment更改为[req.body.comment]

解决了这个问题。您已经在字符串数组类型的模型中定义了注释,但在更新时,您直接传递单个字符串,请以数组格式传递

Posts.update({
        comment: [req.body.comment]
    },
    {
        where: {
            id: req.params.id
        }
    }).then((post) => {
    res.send(post)
}).catch((err) => {
    console.log("err", err);
});

检查req.body.comment并将其作为数组发送


req.body.comment=['test']

您请求的内容类型是什么?你能记录req.body.comment吗?req.body工作正常我已经这样做了,我还通过将req.body.comment更改为[req.body.comment]很好地解决了这个问题,所以请为有相同问题的人发布你的答案