Python Django Model:int()参数必须是字符串、类似字节的对象或数字,而不是';元组';

Python Django Model:int()参数必须是字符串、类似字节的对象或数字,而不是';元组';,python,django,Python,Django,My models.py: class Channel(models.Model): title = models.CharField(max_length=255) def snapshot_statistics(self): new_channel_stat = ChannelStatistic(channel=self) new_channel_stat.save() class ChannelStatistic(models.Mode

My models.py:

class Channel(models.Model):
    title = models.CharField(max_length=255)

    def snapshot_statistics(self):
        new_channel_stat = ChannelStatistic(channel=self)
        new_channel_stat.save()


class ChannelStatistic(models.Model):
    channel = models.ForeignKey(Channel, on_delete=models.CASCADE)
    view_count = models.IntegerField(default=0)

    def save(self, *args, **kwargs):
        self.view_count = 3,
        super(ChannelStatistic, self).save(*args, **kwargs)
触发snapshot_statistics()时,出现以下错误:

int() argument must be a string, a bytes-like object or a number, not 'tuple'
在django调试中,我可以看到:

values  
[(<django.db.models.fields.related.ForeignKey: channel>, None, 35),
 (<django.db.models.fields.IntegerField: view_count>, None, (3,)),
值
[(,无,35),
(,无,(3,),
django将我对view_count属性a的赋值3视为元组

这种行为是怎么回事? 我怎样才能解决它


提前感谢!

这里有一个不必要的逗号:

self.view_count = 3,

这将创建一个元组。

是的,您确实分配了一个元组:
self.view\u count=3,
。看到那个逗号了吗?非常感谢。我应该在通宵工作时多休息。;)非常感谢。我应该在通宵工作时多休息。)