Truncating data in custom tables


This works to remove all entries in a custom table:

$modx->removeCollection(‘objectName’, array());

but the auto-increment doesn’t get reset to 0, like it does if you use the “truncate” command in mySql. Is there some way to reset auto increment in MODX?

Using the truncate command.

OK, I found this and it works:

    $modx->exec("TRUNCATE TABLE {$modx->getTableName('Watering')}");

Is that still going to work in MODX 3?

1 Like

$modx->exec('TRUNCATE TABLE ' . $modx->getTableName($class));

Yes, that will still work.


So, why doesn’t removeCollection reset the autoincrement? Why would anyone not want to reset that if they are deleting all the entries in a table?

Remove collection is for running a DELETE with criteria. Why WOULD it reset the auto-increment? How would it know all records were removed?

I guess that answers my question! Thanks.