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

标签 mysql postgresql symfony insert doctrine

在 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/

相关文章:

php - Symfony2 : Removing entity from middle of collection

mysql - 如何运行并发 SQL 查询?

cloudfoundry 上的 PostgreSQL 抛出 PSQLException : FATAL: terminating connection due to administrator command

mysql - 优化 GROUP BY 性能 - 查询时间大约增加五秒

postgresql - SQLAlchemy:在多对多关系上执行 LEFT JOIN 时的复杂 ON 子句

postgresql - 在 postgresql 9.4 中强制进行 GIN 索引扫描

php - 使 rabbitmq-consumer 中的学说 ORM 缓存失效 |交响乐2

php - Doctrine可为空的一对一关系仍然要创建唯一索引

PHP OOP query() 错误 - 调用未定义的方法 connection::query()

mysql - 如何在MySql中返回具有相同列值的行