Django迁移Many2Many通过模型,ValueError:无法改变字段

时间:2015-07-23 10:56:40

标签: django django-migrations manytomanyfield

嘿伙计们,我想要对多个领域进行排序,在这种情况下,我想要through。我的代码看起来像这样:

class SkirunRatePoint(models.Model):
    latitude = models.DecimalField(u'lat', max_digits=10, decimal_places=6)
    longitude = models.DecimalField(u'lng', max_digits=10, decimal_places=6)
    elevation = models.DecimalField(max_digits=10, decimal_places=6, blank=True, null=True)
    name = models.CharField(u'Name', max_length=200, blank=True, null=True)

    class Meta:
        verbose_name = u'Point'
        verbose_name_plural = u'Points'

    def __unicode__(self):
        return unicode('{0} / {1}'.format(self.latitude, self.longitude))

class SkirunRoute(models.Model):
    skirun = models.ForeignKey(Skirun, verbose_name=u'Path')
    ratepoints = models.ManyToManyField(
    SkirunRatePoint,
    through="SkirunRatePointThrough",
    verbose_name=u'Points',
    blank=True,
)
    class Meta:
        verbose_name_plural = u'trasy z punktami'
        def __unicode__(self):
            return unicode(self.skirun)

class SkirunRatePointThrough(models.Model):
     skirunroute = models.ForeignKey(SkirunRoute, related_name="skirun_route")
     skirunratepoint = models.ForeignKey(SkirunRatePoint, related_name="skirun_rate_points")

     order = models.IntegerField(
         blank=True,
         null=True,
     )

不要介意缩进,可以在我的电脑上找到它们。

Makemigrations一切正常,但是当我尝试迁移时,它会抛出一个错误,上面写着:

ValueError: Cannot alter field skirun.SkirunRoute.ratepoints into skirun.SkirunRoute.ratepoints - they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields)

任何想法可能是什么问题?

0 个答案:

没有答案