class UUIDField(**options)
[source]
A field for storing universally unique identifiers. Uses Python’s UUID
class. When used on PostgreSQL, this stores in a uuid
datatype, otherwise in a char(32)
.
Universally unique identifiers are a good alternative to AutoField
for primary_key
. The database will not generate the UUID for you, so it is recommended to use default
:
1 2 3 4 5 6 | import uuid from django.db import models class MyUUIDModel(models.Model): id = models.UUIDField(primary_key = True , default = uuid.uuid4, editable = False ) # other fields |
Note that a callable (with the parentheses omitted) is passed to default
, not an instance of UUID
.
Please login to continue.