Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#1819 closed (fixed)

[patch] Inspectdb generates CharFields with null

Reported by: remco@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: master
Severity: minor Keywords:
Cc: mir@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Inspectdb generates CharFields with null=true for mysql tables that have attributes which allow Null values. This is not Django convention:

"null

If True, Django will store empty values as NULL in the database. Default is False.

Note that empty string values will always get stored as empty strings, not as NULL -- so use null=True for non-string fields such as integers, booleans and dates.

Avoid using null on string-based fields such as CharField and TextField unless you have an excellent reason. If a string-based field has null=True, that means it has two possible values for "no data": NULL, and the empty string. In most cases, it's redundant to have two possible values for "no data;" Django convention is to use the empty string, not NULL."

-- source: http://www.djangoproject.com/documentation/model_api/

Attachments (1)

textfield_null.diff (476 bytes) - added by mir@… 11 years ago.
patch

Download all attachments as: .zip

Change History (4)

comment:1 Changed 11 years ago by mir@…

Cc: mir@… added
Summary: Inspectdb generates CharFields with null=true while this is not Django convention[patch] Inspectdb generates CharFields with null=true while this is not Django convention
Version: magic-removalSVN

Yes, you're right. Here's a patch, worked for me. Can you check it?

Changed 11 years ago by mir@…

Attachment: textfield_null.diff added

patch

comment:2 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [2872]) Fixed #1819 -- inspectdb no longer puts null=True for TextField and CharField. Thanks, mir@…

comment:3 Changed 10 years ago by Go

Summary: [patch] Inspectdb generates CharFields with null=true while this is not Django convention[patch] Inspectdb generates CharFields with null
Type: defect
Note: See TracTickets for help on using tickets.
Back to Top