#16104: inspectdb of a Mysql table fails to add null=True for Varchars
-------------------------------------+-------------------------------------
Reporter: barracel | Owner: nobody
Type: Bug | Status: closed
Milestone: | Component: Core (Management
Version: 1.3 | commands)
Resolution: invalid | Severity: Normal
Triage Stage: | Keywords:
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):
* status: new => closed
* needs_docs: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
Quoting https://docs.djangoproject.com/en/dev/ref/models/fields/#null:
> Note that empty string values will always get stored as empty strings,
not as NULL. Only use null=True for non-string fields such as integers,
booleans and dates.
[[BR]]
`inspectdb` implements this convention: it ensures that !TextFields and
!CharFields never get `null=True` with the following code:
{{{
if row[6]: # If it's NULL...
extra_params['blank'] = True
if not field_type in ('TextField(', 'CharField('):
extra_params['null'] = True
}}}
[[BR]]
Quoting https://docs.djangoproject.com/en/1.3/ref/django-admin/#inspectdb:
> This feature is meant as a shortcut, not as definitive model generation.
After you run it, you'll want to look over the generated models yourself
to make customizations.
[[BR]]
Nothing prevents you from adding the `null=True`, but in general it's a
bad idea and `inspectdb` won't do it — read the first link above to learn
why.
As a conclusion, it's a feature, not a bug :)
--
Ticket URL: <https://code.djangoproject.com/ticket/16104#comment:1>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.