$result = $db->strict(false)
->field($allowFields)
->replace($this->replace)
->insert($this->data, false, $sequence);
// 获取自动增长主键
if ($result && $insertId = $db->getLastInsID($sequence)) {
$pk = $this->getPk();
if (is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) {
$this->data[$pk] = $insertId;
}
}这里的insert 会查询一次主键 ,然后getLastInsID 再查询的时候就是0了提供一个临时解决方法
vendor\topthink\think-orm\src\db\PDOConnection.php->insert()
// $lastInsId = $this->getLastInsID($query, $sequence);
$lastInsId = 0;使用 create 就可以获得主键了如果更改了之后遇到其他问题 欢迎指正
最佳答案