首页 文章

Django模型字段默认为空

提问于
浏览
46

我需要让我的Django应用程序允许我为某个模型字段设置一个默认值NULL . 我查看了null,空白和默认参数,但是's not very clear what combination of the three I need to use to get the desired effect. I'尝试设置 default=NULL 但是它引发了错误 . 如果我指定 blank=True, null=True 并且没有默认值,那么它是否会默认返回NULL来运行时?

3 回答

  • 27

    试试 default=None . python 中没有 NULL .

  • 0

    如果在模型字段上指定null = True,则如果用户未提供值,则该值将在数据库中存储为NULL .

  • 82
    blank=True #  means in django Admin, it allow you input nothing and keep it empty.
    null = True # mean the field in database is allow to be empty.
    default = None # make the database field None by default.
    

相关问题