gpt4 book ai didi

mysql - lastInsertId(tableName_id_seq) 返回 :Undefined table: 7 ERROR: relation "tableName_id_seq" does not exist

转载 作者:行者123 更新时间:2023-11-29 05:50:48 28 4
gpt4 key购买 nike

在 foreach 中将数据插入到我的表中,我需要插入最后一个 ID。

我正在插入第一个实体,获取 ID 并插入一个与此 ID 链接的子实体。

数据库 POSTGRES - ENV Symfony 4

代码:

$conn = $em->getConnection();
//Here i do an Insert ( always an INSERT )
$Id = $conn->lastInsertId('tableName_id_seq');

这个返回: 未定义表:7 错误:关系“tableName_id_seq”不存在

我觉得我的序列不是在数据库中创建的在调用 lastInsertID 之前我没有关闭连接它总是在 lastInsertID 之前取消插入

这个查询:

select sequence_schema, sequence_name from information_schema.sequences;

返回 0 行

最佳答案

使用 MySQL 你不需要提供 tableName_id_seq

你能试试$Id = $conn->lastInsertId();

关于mysql - lastInsertId(tableName_id_seq) 返回 :Undefined table: 7 ERROR: relation "tableName_id_seq" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54521043/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com