Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#1819 closed (fixed)

[patch] Inspectdb generates CharFields with null

Reported by: remco@… Owned by: adrian
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@… 9 years ago.
patch

Download all attachments as: .zip

Change History (4)

comment:1 Changed 9 years ago by mir@…

  • Cc mir@… added
  • Summary changed from Inspectdb generates CharFields with null=true while this is not Django convention to [patch] Inspectdb generates CharFields with null=true while this is not Django convention
  • Version changed from magic-removal to SVN

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

Changed 9 years ago by mir@…

patch

comment:2 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:3 Changed 9 years ago by Go

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