教义2. orm:schema-tool:update。设定开始编号 [英] Doctrine 2. orm:schema-tool:update . Set start id

查看:61
本文介绍了教义2. orm:schema-tool:update。设定开始编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 ./ bin / doctrine orm:fixtures:load 填充具有示例数据的表时,首先进行迁移时会设置自动增量表ID(例如1,2,3,4) ,5等...

When I use ./bin/doctrine orm:fixtures:load to populate tables with sample data first migration sets auto incremental table id like 1,2,3,4,5 etc...

第二次 orm:fixtures:load 迁移命令后,它将清除所有数据并设置ID像5,6,7,8,9等等...

After second orm:fixtures:load migration command it purges all data and sets ids like 5,6,7,8,9 and so on...

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

How can I reset AI id counter to 1 when I load fixtures many times?

推荐答案

$应用程序/控制台帮助原则:装置:负载

默认情况下,Doctrine Data Fixtures使用DELETE语句从数据库
中删除现有行。如果要使用TRUNCATE语句,则可以使用--purge-with-truncate标志:

By default Doctrine Data Fixtures uses DELETE statements to drop the existing rows from the database. If you want to use a TRUNCATE statement instead you can use the --purge-with-truncate flag:

./app/console doctrine:fixtures:load --purge-with-truncate

截断将重置自动增量。

更新

控制台命令用于Symfony,但仅在使用Doctrine时应相同:

The console command is for Symfony, but it should be the same using Doctrine only:

./bin/doctrine orm:fixtures:load --purge-with-truncate

关于抛出异常的注释的更新#2

UPDATE #2 for the comment about throwing an exception

如果您有外键,您只能通过常规SQL重置 AUTO_INCREMENT

If you have foreign keys, you can only reset the AUTO_INCREMENT through regular SQL:

$connection = $this->getEntityManager()->getConnection();
$connection->exec("ALTER TABLE <tablename> AUTO_INCREMENT = 1;");

这篇关于教义2. orm:schema-tool:update。设定开始编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆