Yii2 在事务回滚时重置数据库 ID
Yii2 reset db ids when transaction rollback
我注意到事务回滚,主键 ID 不断增长。是否有可能以某种方式重置它们(自动递增)?
我猜你正在使用 delete() in your safeDown()
method. if you want to remove all data from the table, you should use truncateTable() or you can write your own slq with execute()。
尝试将 AUTO_INCREMENT 设置为 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.
}
我注意到事务回滚,主键 ID 不断增长。是否有可能以某种方式重置它们(自动递增)?
我猜你正在使用 delete() in your safeDown()
method. if you want to remove all data from the table, you should use truncateTable() or you can write your own slq with execute()。
尝试将 AUTO_INCREMENT 设置为 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.
}