我正在使用express js作为后端构建一个小博客,但我面临一个问题:我在控制台中收到了这个错误
列中的空值"内容博客;关系式";博客;违反非空约束
代码:
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'
})
}
});
}
您正试图将null
或undefined
变量插入到postgresql表中。
检查req.body.contentBlog
的值。