{{{
class Foo(models.Model):
foo_file = models.FileField(null=True)
}}}
which allows null values, if I create a foo object, the `foo_file` field
appears to be `None` by default, as I would expect. But on save, it is
converted to an empty string:
{{{
>>> f = Foo()
>>> f.foo_file.name == ''
False
>>> f.foo_file.name == None
True
>>> f.save()
>>> f = Foo.objects.get()
>>> f.foo_file == ''
True
}}}
This is both unexpected, and also makes `null=True` a bit pointless for
`FileField`.
If it is really by design that file fields cannot be null, setting
`null=True` on the field should be an error and the field should have
`default=''` by default. Although I think it would be better for
`FileField(null=True)` to work more like other fields.
--
Ticket URL: <https://code.djangoproject.com/ticket/25528>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_docs: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
Duplicate of #10244
--
Ticket URL: <https://code.djangoproject.com/ticket/25528#comment:1>