This would most likely be because the update occurs before the row gets inserted into the database, so the row is not found and the update cannot be made. The insert may take longer when there are higher names due to having more items in the database already, so that would explain the error occurring more on higher numbers.
What you can do is to just insert the thumbnail and the regular image name at the same time, which would eliminate the need to insert and then update. Is there a reason you can't do the insert all at the same time?