Django模型,如何将现有的UUID字段转换为外键?

时间:2018-01-11 10:42:23

标签: python django django-models django-migrations

我有和现有的数据库,我有models.py如下:

class basicData(models.Model):

    companyId = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    companyName  = models.CharField(max_length=1000,null=True)
    emailIdCompany = models.EmailField(max_length=1000,blank=False,null=True)
    numberOfEmployees = models.CharField(max_length=1000,null=True)
    contactNumberCompany = models.CharField(max_length=1000,null=True)

class extraData(models.Model):

   companyId = models.UUIDField(default=uuid.uuid4, editable=False)
   interaction = JSONField(db_index=True,null=True)

我想更新models.py,如下所示:

class basicData(models.Model):

        companyId = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
        companyName  = models.CharField(max_length=1000,null=True)
        emailIdCompany = models.EmailField(max_length=1000,blank=False,null=True)
        numberOfEmployees = models.CharField(max_length=1000,null=True)
        contactNumberCompany = models.CharField(max_length=1000,null=True)

class extraData(models.Model):

    companyId = models.ForeignKey(globalcompaniesbasicdatabase)
    interaction = JSONField(db_index=True,null=True)

如何在不丢失数据的情况下执行此操作。

0 个答案:

没有答案