如何清空django中的多对多字段

How to empty a many to many field in django

我想清空以下多对多字段中的所有内容(weekday_with_class):

 all_existing_class.weekday_with_class = None

这是models.py:

   weekday_with_class = models.ManyToManyField('Weekday', blank=True, related_name='weekday_with_class')

但是,如果我执行上面的代码,我会得到这个错误:

Direct assignment to the forward side of a many-to-many set is prohibited. Use weekday_with_class.set() instead.

如何让我的 weekday_with_class 基本上为空?谢谢,如果您需要更多信息,请发表评论。

all_existing_class.weekday_with_class.clear()