假设我创建了两个模型:
class Car(models.Model):
name = models.CharField(max_length=50)
size = models.IntegerField()
class Manufacturer(models.Model):
name = models.CharField(max_length=50)
country = models.CharField(max_length=50)
car = models.ManyToManyField(Car)
我向两个模型添加了项目,然后意识到每辆汽车只与一个制造商相关联。因此,我应该将ManyToManyField转换为ForeignKey:
class Car(models.Model):
name = models.CharField(max_length=50)
size = models.IntegerField()
manufacturer = models.ForeignKey(Manufacturer)
class Manufacturer(models.Model):
name = models.CharField(max_length=50)
country = models.CharField(max_length=50)
我怎样才能转换格式而不丢失我的条目?我查看了South文档但是没有找到这种转换方式...
ForeignKey('Manufacturer')
。 - Thomas Orozco