Php 学说2。orm:schema工具:更新。设置起始id

Php 学说2。orm:schema工具:更新。设置起始id,php,doctrine-orm,fixtures,Php,Doctrine Orm,Fixtures,当我使用/bin/orm:fixtures:load用示例数据填充表时,第一次迁移设置自动增量表id,如1,2,3,4,5等 在第二个orm:fixtures:loadmigration命令之后,它将清除所有数据并设置ID,如5、6、7、8、9等等 当我多次加载装置时,如何将AI id计数器重置为1?$app/console帮助原则:装置:加载 默认情况下,条令数据装置使用DELETE语句从中删除现有行 数据库。如果要改用TRUNCATE语句,可以使用--purge with TRUNCATE标

当我使用
/bin/orm:fixtures:load
用示例数据填充表时,第一次迁移设置自动增量表id,如1,2,3,4,5等

在第二个
orm:fixtures:load
migration命令之后,它将清除所有数据并设置ID,如5、6、7、8、9等等


当我多次加载装置时,如何将AI id计数器重置为1?

$app/console帮助原则:装置:加载

默认情况下,条令数据装置使用DELETE语句从中删除现有行 数据库。如果要改用TRUNCATE语句,可以使用--purge with TRUNCATE标志:

./app/console doctrine:fixtures:load --purge-with-truncate
Truncate将重置自动增量

更新

console命令用于Symfony,但仅在使用原则时应相同:

./bin/doctrine orm:fixtures:load --purge-with-truncate
更新#2以获取有关引发异常的评论

如果您有外键,则只能通过常规SQL重置
自动增量

$connection = $this->getEntityManager()->getConnection();
$connection->exec("ALTER TABLE <tablename> AUTO_INCREMENT = 1;");
$connection=$this->getEntityManager()->getConnection();
$connection->exec(“更改表自动增量=1;”);

在Zend 2中,我使用了下面提到的代码将自动增量值截断并重置为1。在存储库中使用此代码

// To delete all records
$queryBuilder = $this->createQueryBuilder('c');
$queryBuilder->delete();
$queryBuilder->getQuery()->execute();

//Reset table auto increment.
$tableName = $this->getClassMetadata()->getTableName();
$connection = $this->getEntityManager()->getConnection();
$connection->exec("ALTER TABLE " . $tableName . " AUTO_INCREMENT = 1;");

抛出异常:语法错误或访问冲突:1701无法截断外键约束中引用的表I'm lil扩展代码,适用于simony3:$em=$this->container->get(“条令”)->getManager()$tableName=$em->getClassMetadata('AcmeWebBundle:NameEntity')->getTableName()$connection=$em->getConnection()$connection->exec(“altertable”。$tableName.“AUTO_INCREMENT=1;”);