1

我正在为后端使用 express js 构建一个小博客,但我遇到了一个问题:我在控制台中收到此错误

关系“blog”的“contentblog”列中的空值违反了非空约束

代码:

const connection = require('../DatabaseConnection/db')

module.exports.Add = function (req, res) {
    const blog = {
        title: req.body.title,
        contentBlog: req.body.contentBlog,
    }
    connection.query('INSERT INTO blog(contentBlog) values($1)', [blog.contentBlog], function (error, results, fields) {
        if (error) {
            res.json({
                status: false,
                message: 'there are some errors with the query'
            })
            console.log(error)
        } else {
            res.json({
                status: true,
                data: results,
                message: 'Post has been added successfully'
            })
        }
    });
}
4

1 回答 1

0

您正在尝试将nullorundefined变量插入到您的 postgresql 表中。

检查 的值req.body.contentBlog

于 2021-01-02T10:04:04.050 回答