Opened 14 years ago
Closed 14 years ago
#16104 closed Bug (invalid)
inspectdb of a Mysql table fails to add null=True for Varchars
| Reported by: | barracel | Owned by: | nobody | 
|---|---|---|---|
| Component: | Core (Management commands) | Version: | 1.3 | 
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
Using inspectdb for the following table:
Code highlighting:
CREATE TABLE `test` ( `test_int` bigint DEFAULT NULL, `test_varchar` varchar(100) DEFAULT NULL);
I get the model:
Code highlighting:
class Test(models.Model): test_int = models.BigIntegerField(null=True, blank=True) test_varchar = models.CharField(max_length=300, blank=True) class Meta: db_table = u'test'
test_varchar definition contains null=True but test_int does not
  Note:
 See   TracTickets
 for help on using tickets.
    
Quoting https://docs.djangoproject.com/en/dev/ref/models/fields/#null:
inspectdbimplements this convention: it ensures that TextFields and CharFields never getnull=Truewith the following code:if row[6]: # If it's NULL... extra_params['blank'] = True if not field_type in ('TextField(', 'CharField('): extra_params['null'] = TrueQuoting https://docs.djangoproject.com/en/1.3/ref/django-admin/#inspectdb:
Nothing prevents you from adding the
null=True, but in general it's a bad idea andinspectdbwon't do it — read the first link above to learn why.As a conclusion, it's a feature, not a bug :)