从UUID主键还原为整数主键

时间:2019-05-21 08:12:40

标签: django python-3.x

我使用UUID作为主键并将其删除。现在,还原为默认值后会引发错误。

我尝试将CharFieldprimary_key=True一起使用,删除了数据库并进行了迁移。但是它仍然抛出以下错误:

回溯:

django.db.utils.ProgrammingError: cannot cast type uuid to integer
LINE 1: ..._biodata" ALTER COLUMN "id" TYPE integer USING "id"::integer

MODELS.PY

class BioData(models.Model):
    status = models.CharField(max_length=200, 
    choices=CANDIDATE_CHOICES, default='NOT ONBOARDED')
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    email = models.EmailField(max_length=70, blank=True)
    mobile = models.CharField(max_length=100, blank=False)
    contact_number = models.CharField(max_length=100, blank=True, 
    null=True)
    gender = models.CharField(max_length=200, choices=GENDER_CHOICES)
    marital_status = models.CharField(max_length=200, 
    choices=MARITAL_STATUS_CHOICES)
    date_of_birth = models.DateField(null=True, blank=True)
    next_of_kin = models.ForeignKey(NextOfKin, 
    on_delete=models.CASCADE)
    address = models.ForeignKey(Address, on_delete=models.CASCADE)

我想恢复为默认的增量“整数” ID,而无需明确声明id

0 个答案:

没有答案