Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django python blank=True仍然需要_Python_Django_Field - Fatal编程技术网

django python blank=True仍然需要

django python blank=True仍然需要,python,django,field,Python,Django,Field,在下面的代码中,仍然需要具有blank=True的字段,这些字段不能为Null 例如: # Skill train timer class SkillTrainingTimer(models.Model): """ Character Training timer, keep track fo what skill is in training, and when it is done """ character = models.ForeignKey(

在下面的代码中,仍然需要具有
blank=True
的字段,这些字段不能为
Null

例如:

# Skill train timer
    class SkillTrainingTimer(models.Model):
    """
    Character Training timer,  keep track fo what skill is in training, and when it is done
    """
    character = models.ForeignKey(Character, unique=True)
    skill = models.ForeignKey(Skill, blank=True)
    trainingground = models.ForeignKey(TrainingGround, verbose_name='Training ground')
    timer = models.DateTimeField()
现在我做到了:

train_skill = SkillTrainingTimer(
        character=some_character_obj,
        trainingground=some_trainingground_obj,
        timer = fatetime.datetime.now()
)
train_skill.save()

它不能为
Null
。我在很多模型和函数中都有这个功能,到目前为止,我只是在其中转储了一些无用的数据

您必须在字段定义上添加
null=True
参数,最好在syncdb之前(或者您可以使用South迁移)


您必须在字段定义上添加
null=True
参数,最好在syncdb之前添加(或者您可以使用South迁移)


对于外键,除了NULL之外,实际上没有有效的空值。实际上,在数据库端,您需要为该外键输入NULL或一些有效值

因此,要允许输入外键,还需要添加
null=True
。这将在数据库中输入空白值,如
NULL


但是,对于像
models.String
这样的字段,建议使用简单的
blank=True
,其中存在除
NULL
之外的另一个空值,即空字符串。这允许您使用
NULL
来区分从未填充的字段和已填充空白值的字段。区别很小,通常不需要,但也可以作为一项要求(尽管文档中不建议这样做)。

对于外键,除了NULL之外,实际上没有有效的空白值。实际上,在数据库端,您需要为该外键输入NULL或一些有效值

因此,要允许输入外键,还需要添加
null=True
。这将在数据库中输入空白值,如
NULL


但是,对于像
models.String
这样的字段,建议使用简单的
blank=True
,其中存在除
NULL
之外的另一个空值,即空字符串。这允许您使用
NULL
来区分从未填充的字段和已填充空白值的字段。区别很小,通常不需要,但可以作为一项要求(尽管文档中不建议这样做)。

null=True
在数据库中的列上设置null


blank=True
确定表单中是否需要该字段。这包括管理员和您自己的自定义表单。如果
blank=True
则不需要该字段,而如果为False,则该字段不能为空。希望这有帮助

null=True
在数据库中的列上设置null


blank=True
确定表单中是否需要该字段。这包括管理员和您自己的自定义表单。如果
blank=True
则不需要该字段,而如果为False,则该字段不能为空。希望这有帮助

哇,这个答案是很久以前做出的。读《南方》给我带来了怀旧。哦,这个答案是很久以前做出的。读《南方》让我怀旧
skill = models.ForeignKey(Skill, blank=True, null=True)