0

I've noticed by transactions rollbacks, primary key ids keep growing. Is it possible somehow to reset them (auto increment)?

Misa Lazovic
  • 2,805
  • 10
  • 32
  • 38
user2511599
  • 796
  • 1
  • 13
  • 38

2 Answers2

0

I guess you are using 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().

Clyff
  • 4,046
  • 2
  • 17
  • 32
  • Unfortunately I can't truncate, but this question seems lame, according to this thread: http://stackoverflow.com/questions/2214141/auto-increment-after-delete-in-mysql – user2511599 Jan 31 '16 at 07:59
0

Try set AUTO_INCREMENT to 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.
}
BSCheshir
  • 69
  • 2
  • 5