【发布时间】:2017-09-13 21:14:24
【问题描述】:
这是我的表(CELLID)结构。
+---------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------+------+-----+---------+-------+
| CELL_ID | int(11) | NO | PRI | NULL | |
| STATUS | tinyint(4) | NO | | NULL | |
+---------+------------+------+-----+---------+-------+
这是我要插入表格的代码。
knex('CELLID').insert(insertObj)
.then(function (result) {
_log.info(reqContainer.uuid, "Successfully Added To CELLID||", result)
// respond back to request
_log.info(reqContainer.uuid, "Exiting CELLID_S");
return resolve(result) // respond back to request
})
.catch(function (err) {
_log.error(reqContainer.uuid, "Failed Adding To CELLID ||", err)
_log.error(reqContainer.uuid, "Exiting CELLID_S");
// respond back to request
return reject(Error("Failed Adding CELLID"));
})
成功插入后,必须返回 ID。在我的情况下不会发生这种情况。我总是在插入时得到 ID 为 0。
我曾尝试添加一个额外的列,自动递增主键 ID(将 CELL_ID 删除为 PK)。在这种情况下,我得到了 ID(自动递增值)。
我在这里错过了什么?
谢谢。
【问题讨论】:
-
返回 0 id 时,您可以检查实际插入数据库的内容吗?如果将 id 列的名称更改为
id而不是CELL_ID,是否有帮助? -
不,如果我将 id 列的名称更改为
id而不是CELL_ID也没关系。我想我们得到插入的id,只有当我们的id是自动生成(自动增量)。 -
同样的问题,不知道为什么:(
-
.returning() is not supported by mysql and will not have any effect.可能是因为这个 -
.returning() 不受 sqlite3 支持,不会有任何效果。