I\'m working with an API that wants me to generate opaque \"reference IDs\" for transactions with their API, in other words, unique references that users can\'t guess or infer i
Random integers are not unique, and primary keys must be unique. Make the key field a char(32) and try this instead:
from uuid import uuid4 as uuid randomRef = uuid().hex
UUIDs are very good at providing uniqueness.