lastInsertId(tableName_id_seq)返回:未定义表:7 ERROR:关系“tableName_id_seq”不存在

问题描述 投票:1回答:2

在foreach我的表中插入数据,我需要有最后的ID插入。

林将第一实体,拿到编号,并插入一个孩子的实体,与此ID链接。

数据库POSTGRES - ENV的Symfony 4

代码:

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

这回:不确定表:7 ERROR:关系“tableName_id_seq”不存在

我觉得我的顺序没有在DB中创建我不关闭Connexion公司前调用lastInsertID桃李lastInsertID前未插入

此查询:

select sequence_schema, sequence_name from information_schema.sequences;

返回0行

mysql postgresql symfony insert doctrine
2个回答
2
投票

随着MySQL你不需要提供tableName_id_seq

你可以尝试$Id = $conn->lastInsertId();


0
投票

那么没有办法使用lastinsertId(),我发现我的方式使用

RETURNING id 

在查询中,然后经过

$preparedQuery->execute()

我做了

$preparedQuery->fetchAll()
© www.soinside.com 2019 - 2024. All rights reserved.