django.db.utils.IntegrityError(无法创建唯一索引)

时间:2019-06-20 13:18:15

标签: django-models uuid

当尝试在现有django模型中添加新的Unique_id(uuid)字段时,它会返回整数错误。

models.py:
     class Directory(models.Model):

    unique_id =   models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
    name    =    models.CharField(max_length=120)
    path    =    models.CharField(max_length=240)

Views.py:
def get_dir_dict(request, dir):
    dir_info['pk']       = query.pk
    dir_info['unique_id']  = query.unique_id
    dir_info['name']     = query.name
    dir_info['path']     = query.path


error:
File "/home/sitharth/zeal/lib64/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: could not create unique index "zkloud_directory_unique_id_key"
DETAIL:  Key (unique_id)=(734e8926-386b-47a9-9ac0-d617f45f7113) is duplicated.

0 个答案:

没有答案