假设我创建了两个模型:
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 文档,但没有找到这种转换方式...