2

How can I alter table or reset the auto-increment of a field in Yii 1.x, using CDbMigration?

I found alterColumn method, as good as createTable, dropTable, renameTable and truncateTable methods, but either I'm blind or there isn't anything for altering table or resetting the auto-increment of particular column or field.

Community
  • 1
  • 1
trejder
  • 17,148
  • 27
  • 124
  • 216

1 Answers1

2

You can use execute() as Yii defines it:

Executes a SQL statement. This method executes the specified SQL statement using dbConnection.

So,

$this->execute("ALTER TABLE tbl_name AUTO_INCREMENT = 1");
Ali MasudianPour
  • 14,329
  • 3
  • 60
  • 62
  • Thank you, perfect answer. I have a [similar](http://stackoverflow.com/q/27403885/1469208) problem, covering `CDbMigration`. Maybe you can help as well? – trejder Dec 10 '14 at 14:49
  • starting from YY 2.0.16 you can do it this way `$this->executeResetSequence('tbl_name', '1');` – MoVod Aug 31 '18 at 04:13