postgresql - 尝试将数据传递到数据库时发生错误:(错误:列“名称”不存在)
问题描述
我目前正在尝试将数据从快速后端传递到数据库。原始数据是从 REST 前端传递的(我猜此时并不重要)。
我的帖子功能看起来如下:
c_app.post('/v1/postAccount', function (req, res) {
console.log(req.body);
{ try
{ const { request } = req.body;
const newAccount = c_pool.query(`INSERT INTO "account"("name", "firstname", "email", "password", "is_admin")
VALUES(
json_attr_value_d_untainted($2, name, NULL),
json_attr_value_d_untainted($2, firstname, NULL),
json_attr_value_d_untainted($2, email, NULL),
($2->>password)::TEXT,
COALESCE(($2->>isAdmin )::BOOLEAN, false)
) RETURNING *`, [request]);
res.status(200).json(newAccount);
}
catch (error)
{ console.log(error);
res.status(500).json({_type_: 'ERROR', _status_: 500, _message_: error.message});
}
}
})
我之前定义了 c_app ( c_app = express() )
第一个 console.log 将数据提供给控制台,因此数据正确传递。通过前端传递数据时出现错误:
UnhandledPromiseRejectionWarning: error: column "name" does not exist
数据通过前端的这个函数传递:
async handleSubmit() {
const data = {
name: this.name,
firstname: this.firstname,
email: this.email,
password: this.password
}
const options = {
method: 'POST',
headers: {
'Content-Type': 'applications/json'
},
body: JSON.stringify(data),
}
await axios.post('postAccount', data);
我的数据库结构如下: