【问题标题】:Why does the FileField in the models need a default?为什么模型中的 FileField 需要默认值?
【发布时间】:2014-11-10 07:00:38
【问题描述】:

我正在使用 Django,我正在尝试创建一个文件上传器并在模型中有各种 FileField。当我尝试这样做时,

python manage.py makemigrations

它提示为 FileFields 设置一个默认值,为什么它很重要?它说它是一个不可为空的字段,但为什么它不能为空呢?

【问题讨论】:

    标签: django django-models django-migrations


    【解决方案1】:

    这是因为您没有在模型中设置null=True。如stated in the documentation,Django 中的每个模型字段都可以为空。

    【讨论】:

      【解决方案2】:

      因为 null 和空白的默认值都是 false。检查 here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-23
        • 2018-10-02
        • 1970-01-01
        • 2014-08-13
        • 2013-06-15
        相关资源
        最近更新 更多