If the total number of issued codes, the length of your codes and acceptable Levenshtein distance are small enough, you could build a tree of existing codes and their 'Levenshtein neighbors' in memory to reduce the time to generate a new code to O(ln N). If there are too many codes, you could try creating an additional SQL table containing just the codes and neighbors and rely on SQL for O(ln N) search. When you insert a new code, insert its neighbors together with it.
If you have the flexibility, i.e. you can increase code length by 1 or add a new character to the acceptable character set, or if there is an unused character in some position, the best solution would be to separate the 'old' and 'new' code spaces and generate new ones algorithmically to meet your requirements. This approach was adopted for UUID/GUID when they decided not to use the computer's MAC address in it.