Django

Code

Ticket #1500 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

[patch] MySQL AutoField should be int, not mediumint

Reported by: ejf-django@floehr.com Assigned to: adrian
Milestone: Component: Core framework
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I believe that the AutoField mapping in core/db/backends/mysql.py DATA_TYPES should be changed from:

'AutoField?': 'mediumint(9) unsigned auto_increment'

to:

'AutoField?': 'int(10) unsigned auto_increment'

However, currently MySQL ForeignKey references go to 'int(11)', or signed integers. I'm not really clear where in the code that is happening, but ForeignKey references should be changed to unsigned ints.

There are several reasons for this:

  • We are arbitrarily limiting the table size, with the only benefit being one byte saved per row (mediumint storage is 3 bytes, int is 4)
  • INT is the canonical primary key for MySQL
  • PostgreSQL serial defaults to an INT, and is used as such in Django. Therefore MySQL Django created tables are limited compared to the equivalant Django code run against PostgreSQL. We should strive for equivalency.

Attachments

mysql_autofield_patch.diff (0.6 kB) - added by ejf-django@floehr.com on 03/18/06 16:58:20.
Patch for ticket #1500
mysql_autofield_patch_2.diff (1.3 kB) - added by Andy Dustman <farcepest@gmail.com> on 03/18/06 21:10:45.
Updated patch (files moved, plus additional bugfix)

Change History

03/18/06 16:57:38 changed by ejf-django@floehr.com

  • summary changed from MySQL AutoField should be int, not mediumint to [patch] MySQL AutoField should be int, not mediumint.

Ok, here is the patch to the current trunk changing AutoField? for MySQL to a signed integer. Unsigned int would be better, but because of the way AutoField? gets resolved to a signed integer (see #1165) and the fact that a PostgreSQL serial is signed, it cannot be without much more work. This at least removes an arbitrary table size limitation and makes MySQL generated tables functionally equivalent to PostgreSQL, sqllite, and mssql generated tables.

03/18/06 16:58:20 changed by ejf-django@floehr.com

  • attachment mysql_autofield_patch.diff added.

Patch for ticket #1500

03/18/06 21:10:45 changed by Andy Dustman <farcepest@gmail.com>

  • attachment mysql_autofield_patch_2.diff added.

Updated patch (files moved, plus additional bugfix)

03/18/06 21:16:05 changed by Andy Dustman <farcepest@gmail.com>

mysql_autofield_patch_2.diff is the same fix as the first, only for the magic removal branch. Plus there is a fix for breakage in rev 2528 to django/core/management.py.

03/28/06 11:46:54 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [2582]) Fixed #1500 -- Changed MySQL AutoField? to be integer, not mediumint. Thanks, ejf-django


Add/Change #1500 ([patch] MySQL AutoField should be int, not mediumint)




Change Properties
Action