Knex.js插入在本地工作但不在Heroku部署

时间:2016-01-18 14:05:43

标签: node.js postgresql heroku knex.js

在我的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"

在本地服务器上,请求成功,我在数据库中看到新记录。知道为什么会有所不同吗?谢谢你的帮助!如果其他信息有用,请告诉我。

  • 部署到Heroku
  • node.js v4.2.1
  • express v4.13.1
  • knex v0.9.0
  • pg v4.4.3

0 个答案:

没有答案