Transactions Yii2事务回滚时重置数据库ID

Transactions Yii2事务回滚时重置数据库ID,transactions,yii2,rollback,Transactions,Yii2,Rollback,我注意到,通过事务回滚,主键ID不断增长。是否可以以某种方式重置它们(自动增量)?我猜您正在使用safeDown()方法。如果要从表中删除所有数据,应使用或可以使用编写自己的slq。尝试将自动增量设置为1 public function down() { $this->delete('{{%email}}', ['id' => [1, 2, 3, 4, 5, 6, 7, 8, 9,]]); $this->execute('ALTER TABLE {{%email

我注意到,通过事务回滚,主键ID不断增长。是否可以以某种方式重置它们(自动增量)?

我猜您正在使用
safeDown()方法。如果要从表中删除所有数据,应使用或可以使用编写自己的slq。

尝试将自动增量设置为1

public function down()
{
    $this->delete('{{%email}}', ['id' => [1, 2, 3, 4, 5, 6, 7, 8, 9,]]);
    $this->execute('ALTER TABLE {{%email}} AUTO_INCREMENT = 1');
    // When you insert any other (not NULL or 0) value into an AUTO_INCREMENT column,
    // the column is set to that value and the sequence is reset so that the
    // next automatically generated value follows sequentially from the largest column value.
}

不幸的是,我无法截断,但根据以下线索,这个问题似乎站不住脚: