Django (fields.W340) null has no effect on ManyToManyField.
- 2020 年 3 月 9 日
- 筆記
Model定義
class Customer(models.Model): name = models.CharField(verbose_name='客戶名', max_length=128) contact = models.CharField(verbose_name='電話', max_length=11) address = models.CharField(verbose_name='地址', max_length=128) status_choices = ( (0, '意向客戶'), (3, '已報價'), (1, '已拿樣'), (2, '已成交') ) status = models.IntegerField(choices=status_choices, verbose_name='狀態') company = models.CharField(verbose_name='公司名', max_length=128, null=True, blank=True) create_time = models.DateField(verbose_name='創建時間', auto_now=True) product = models.ManyToManyField(Product, verbose_name='意向產品',null=True, blank=True) description = models.TextField(verbose_name='備註', null=True, blank=True)
警告資訊
(fields.W340) null has no effect on ManyToManyField.
解決辦法
這只是一個小小的警告,可以不用處理,如果覺得礙眼,可以把product
欄位的null=True移除
移除後就是這樣的:
product = models.ManyToManyField(Product, verbose_name='意向產品', blank=True)
重啟後,警告就消失了。