本文介紹 django.db.models.UUIDField
的用法。
聲明
class UUIDField(**options)
用於存儲通用唯一標識符的字段。使用 Python 的
類。在 PostgreSQL 上使用時,它存儲在 UUID
uuid
數據類型中,否則存儲在 char(32)
中。
通用唯一標識符是
for AutoField
的一個很好的替代品。數據庫不會為您生成 UUID,因此建議使用 primary_key
:default
import uuid
from django.db import models
class MyUUIDModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# other fields
請注意,可調用對象(省略括號)被傳遞給 default
,而不是 UUID
的實例。
查找PostgreSQL
在 PostgreSQL 上使用
、 iexact
、 contains
、 icontains
、 startswith
、 istartswith
或 endswith
查找不適用於沒有連字符的值;因為PostgreSQL 將它們存儲在帶連字符的 uuid 數據類型中。iendswith
相關用法
- Python Django UniqueConstraint.deferrable用法及代碼示例
- Python Django UniqueConstraint.condition用法及代碼示例
- Python Django Union用法及代碼示例
- Python Django UniqueConstraint.expressions用法及代碼示例
- Python MongoDB Update_one()用法及代碼示例
- Python Django UniqueConstraint.opclasses用法及代碼示例
- Python Django USERNAME_FIELD用法及代碼示例
- Python Unicode轉ASCII用法及代碼示例
- Python Django UserPassesTestMixin.test_func用法及代碼示例
- Python Tableau UserItem用法及代碼示例
- Python PIL UnsahrpMask()用法及代碼示例
- Python Django UniqueConstraint.include用法及代碼示例
- Python Django Upper用法及代碼示例
- Python Union()用法及代碼示例
- Python Django UpdateView.object用法及代碼示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python pandas.arrays.IntervalArray.is_empty用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python numpy.less()用法及代碼示例
- Python Matplotlib.figure.Figure.add_gridspec()用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python Django File.save用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.db.models.UUIDField。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。