Changing from transaction to truncation seems to fix the issue

My guess is the transaction is not rolled back correctly, or the keys
auto increment, but transaction does not cause the autoincrement to
also reset, whereas truncate probably will :-)