我正在为后端使用 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'
})
}
});
}