0

I have a mssql schema with the django ORM / pymssql extension. I have some classes build via the inspectdb function. A lot of the Primarykeys in the tables are UUID fields / mssql uniqueidentifier, which the ORM inspected as CharFields with length 36. I am concerned now with possible duplicates for the primary keys since the tables are growing very fast.

The tables have a default constraint for any new primary key on the database site. So basically I have two (different) sources of UUID generation (the database server and the application server)

How is it possible to insert via the ORM from django performantly? Am I save with generating the UUIDs via pythons uuid module or do I have to ask the database everytime for a new UUID before creating a object with django?

Hubertus
  • 11
  • 3
  • *"I am concerned now with possible duplicates for the primary keys since the tables are growing very fast."* don't be. The chances is significantly small. There are 2^128 different possible values for a GUID. – Thom A Feb 21 '22 at 16:39
  • Does this answer your question? [Is a GUID unique 100% of the time?](https://stackoverflow.com/questions/39771/is-a-guid-unique-100-of-the-time) – Thom A Feb 21 '22 at 16:39
  • Realistically you should only be concerned about clashes if you have *lots* of hosts generating GUIDs and they are all sending those to the same location (that requires uniqueness). – Thom A Feb 21 '22 at 16:42

1 Answers1

0

The primary key cannot be duplicated, so it will raise a "duplicated pk duplicated" exception. In addition, the odds of getting a duplicated uuid is quite close to 0, you will get 3 lottery prizes before you get a duplicated uuid.

xpeiro
  • 733
  • 5
  • 21
  • Lottery prizes, or Jackpots? I've got prizes on the lottery more than 3 times, and I haven't played in years, but never the jackpot. – Thom A Feb 21 '22 at 16:43