我有以下模型类
class GroupstageTournamentModel(ClusterableModel):
#Score of TEAM 1
team_1_first_halftime_score = models.PositiveSmallIntegerField(blank=True, default=None, verbose_name='Resultat 1. HZ')
team_1_first_halftime_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte 1. HZ')
team_1_second_halftime_score = models.PositiveSmallIntegerField(blank=True, default=None, verbose_name='Resultat 2. HZ')
team_1_second_halftime_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte 2. HZ')
team_1_shootout_score = models.PositiveSmallIntegerField(blank=True, default=None, verbose_name='Resultat Shootout')
team_1_shootout_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Schootout Punkte')
team_1_total_score = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Resultat Total')
team_1_total_points = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte Total')
#Score of TEAM 2
team_2_first_halftime_score = models.PositiveSmallIntegerField(blank=True, default=None, verbose_name='Resultat 1. HZ')
team_2_first_halftime_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte 1. HZ')
team_2_second_halftime_score = models.PositiveSmallIntegerField(blank=True, default=None, verbose_name='Resultat 2. HZ')
team_2_second_halftime_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte 2. HZ')
team_2_shootout_score = models.PositiveSmallIntegerField(blank=True, default=None, verbose_name='Resultat Shootout')
team_2_shootout_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Schootout Punkte')
team_2_total_score = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Resultat Total')
team_2_total_points = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte Total')
正如您所看到的,我PositiveSmallIntegerField
的一些deafult=None
是django.db.utils.IntegrityError: NOT NULL constraint failed: tournament_groupstagetournamentmodel.team_1_first_halftime_score
。如果我保存这个模型,我会得到一个错误
Map<String, Optional<List<String>>>
我可以以某种方式忽略此错误并保存此模型吗?我特意把默认值设为无
答案 0 :(得分:0)
我刚刚添加了null=True
,就像@agconti建议的那样。感谢
team_1_first_halftime_score = models.PositiveSmallIntegerField(blank=True, default=None, null=True, verbose_name='Resultat 1. HZ')
team_1_first_halftime_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte 1. HZ')
team_1_second_halftime_score = models.PositiveSmallIntegerField(blank=True, default=None, null=True, verbose_name='Resultat 2. HZ')
team_1_second_halftime_point = models.PositiveSmallIntegerField(blank=True, default=0, verbose_name='Punkte 2. HZ')
team_1_shootout_score = models.PositiveSmallIntegerField(blank=True, default=None, null=True, verbose_name='Resultat Shootout')