簡體   English   中英

關系“博客”的“標題”列中的 Null 值違反非空約束

[英]Null value in column “title” of relation “blog” violates not-null constraint

我正在為后端使用 express js 構建一個小博客,但我遇到了一個問題:我在控制台中收到此錯誤

關系“blog”的“contentblog”列中的 null 值違反非空約束

代碼:

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'
            })
        }
    });
}

您正在嘗試將nullundefined的變量插入 postgresql 表中。

檢查req.body.contentBlog的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM