我在表中有两个主键我知道django在同一个表中不支持多个PK 我使用unique_identifier但是当我执行syncdb时,所有列都没有创建
class SODIOrder(models.Model):
sodi_order_num = models.CharField(max_length=50, primary_key=True)
sodi_order_version = models.CharField(max_length=50,primary_key=True)
service_identifier = models.CharField(max_length=50)
telephone_number = models.CharField(max_length=12)
insert_timestamp = DateTimeUTCField(auto_now_add=True)
class Meta:
unique_together = (("sodi_order_num","sodi_order_version"))
没有创建 sodi_order_version
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:7)
从模型字段中删除primary_key=True
并将unique_together
更改为tuple of tuples
,如下所示:
class SODIOrder(models.Model):
sodi_order_num = models.CharField(max_length=50)
sodi_order_version = models.CharField(max_length=50)
service_identifier = models.CharField(max_length=50)
telephone_number = models.CharField(max_length=12)
insert_timestamp = DateTimeUTCField(auto_now_add=True)
class Meta:
unique_together = (("sodi_order_num","sodi_order_version"),)