在我的Express应用程序中,我想在用户通过发布请求发送数据时创建新记录。我在本地运行时工作,但它在部署的站点中不起作用。
我正在使用knex.js.以下是处理发布请求的路由:
router.post('/', function(req, res) {
newBook = {
title: req.body.title,
genre: req.body.genre,
description: req.body.description,
cover_url: req.body.cover_url
}
Books().insert(newBook, 'id').then(function(result) {
res.send('Created new book with id ' + result)
})
})
这是已部署站点上的错误日志中的内容:
Unhandled rejection error: insert into "books" ("cover_url", "description", "genre", "title") values ($1, $2, $3, $4) returning "id" - duplicate key value violates unique constraint "books_pkey"
在本地服务器上,请求成功,我在数据库中看到新记录。知道为什么会有所不同吗?谢谢你的帮助!如果其他信息有用,请告诉我。