我使用 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/