gpt4 book ai didi

php - 如何使用 doctrine2 设置初始 auto_increment 值

转载 作者:可可西里 更新时间:2023-11-01 06:49:10 24 4
gpt4 key购买 nike

我使用 doctrine2 映射器生成我的 innoDB (mysql) 数据库。如何使用 php 注释设置我的 auto_incremented id 的初始值?

这就是我目前为实体类型的 id 建模的方式。

/**
* @var integer $_id
*
* @Column(name="id", type="integer", nullable=false)
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $_id;

我在文档中找到了以下代码,但它看起来好像会使用单独的表来生成 ID。

/**
* @Id
* @GeneratedValue(strategy="SEQUENCE")
* @Column(type="integer")
* @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
*/

最佳答案

这是在 MySQL 中设置 doctrine 2 中的 auto_increment 的完整代码示例:

$connection = $this->getEntityManager()->getConnection();
$connection->prepare('ALTER TABLE my_table AUTO_INCREMENT = 100;')->execute();

关于php - 如何使用 doctrine2 设置初始 auto_increment 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8022629/

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