Opened 5 years ago
Closed 5 years ago
#31047 closed Bug (duplicate)
Empty models.TextField being incorrectly saved as empty string
Reported by: | Ebenezer Hailemariam | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Steps to reproduce:
- Create a
Model
and add the following field:
foo = models.TextField(blank=True, null=True)
- Create a corresponding
ModelForm
- Create a template to render the form
- Load the template in a browser, leave
foo
blank and submit the form
Django will incorrectly save foo
's value to the DB as empty string instead. It should be stored as null
Change History (2)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Version: | 2.2 → master |
Note:
See TracTickets
for help on using tickets.
I think empty HTML textarea send the value as an empty string instead of null/None.
The only solution may be to set
disabled
attribute for the textarea. In that case, the value for that field will not be submitted to the server andnull
should be saved into the DB instead of the empty string.