Creating django objects with a random primary key

前端 未结 6 1506
面向向阳花
面向向阳花 2021-02-08 12:08

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

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 12:13

    You should be able to set the transactionRef column in your database to be unique. That way, the database will not allow transactions to be added with the same transactionRef value. One possibility is to randomly generate UUIDs -- the probability of random UUIDs colliding is extremely small.

提交回复
热议问题