#23405: Blank-able CharFields require default=''
----------------------------+------------------------------------
Reporter: yuvadm | Owner: coldmind
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Comment (by andrewgodwin):
Just to put some input in on this - the weird quirk of defaulting to empty
string is a feature of the text fields themselves, and it's not just text
fields (for example, one should argue that IntegerFields with `blank=True,
null=False` should have a default value of 0 rather than prompting).
Thus, I think it needs to be addressed on the fields themselves. I doubt
we can change what `has_default()` returns, but there could be an argument
made for adding a new `needs_default()` method, which returns if the field
can happily live without a default (so, for example, a `CharField` would
return `False`, and the new `BooleanField` would return `True` as it needs
an explicit default, though that would get caught in validation).
Then, autodetector can be modified to also check for `needs_default() =
True`. We should also probably upgrade it and warn if it has `unique` set
on it, as doing this when you're adding a `NOT NULL` column is usually a
bad idea if there's data in the table.
--
Ticket URL: <https://code.djangoproject.com/ticket/23405#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.37e36e16d14c9affaff488702e531894%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.