#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 coldmind):

 Replying to [comment:15 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 tsuch checkshere's data in the table.


 Thanks, this is a good idea.
 Few questions about it.
 1. `needs_default()` should return value according to field attributes?
 For example, for `TextField`, it be like

 {{{
     def needs_default(self):
         if self.blank and not self.null and self.default is NOT_PROVIDED:
             return False
         return True

 }}}
 , right?
 2. If 1 question is right, the default value for `needs_default` should be
 `True`?
 3. Do we need override `needs_default` for all fields, or only for
 "special" ?

--
Ticket URL: <https://code.djangoproject.com/ticket/23405#comment:16>
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.8afd2b2dc9991749db10adf3162f87ee%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to