Django

Code

Ticket #56 (reopened)

Opened 3 years ago

Last modified 1 week ago

MySQL id columns should be UNSIGNED

Reported by: Manuzhai <mail@manuzhai.nl> Assigned to: adrian
Milestone: post-1.0 Component: Database layer (models, ORM)
Version: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

This gets you twice the integer space, and seems to me to be a nice sanity check.

Don't know if the same would go for Postgres.

Not enough into the code right know to produce a patch myself.

Attachments

Change History

07/18/05 08:53:59 changed by adrian

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

Fixed in [171]. Thanks!

08/13/08 04:55:19 changed by julianb

  • status changed from closed to reopened.
  • version deleted.
  • resolution deleted.
  • milestone set to 1.0.

This improvement got lost somehow. I spent half an hour looking in the svn logs to see if there was a reason why it's not still an unsigned integer, but I found none.

08/13/08 07:37:42 changed by Karen Tracey <kmtracey@gmail.com>

It 'got lost' intentionally with the fix for #1500. I do not quite follow the statement there: "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." so do not know if it still applies as a reason why MySQL AutoFields cannot be unsigned. However it appears to have been an intentional change at one point so someone who does understand it should verify that switching back to unsigned won't cause any problems before flip-flopping the value again.

08/14/08 11:37:22 changed by julianb

What #1500 says is, that if a foreign key points to an AutoField?, we would need to resolve it to the same unsigned integer in MySQL. Currently foreign keys become IntegerFields?.

If we want to switch keys to unsigned for MySQL, it seems some kind of ForeignKeyField? would be needed, which could then be, like AutoField?, unsigned.

08/14/08 12:21:52 changed by julianb

This issue let me to a bug: #8316

With the patch there, we would have a KeyField? and could change AutoField? and KeyField? to unsigned for MySQL.

08/16/08 17:49:07 changed by mtredinnick

  • milestone changed from 1.0 to post-1.0.

This is an really an enhancement request. If somebody really needs it right now they can alter the table column (plus it won't affect existing setups anyway). It can wait until after 1.0 for reconsideration.

11/26/08 04:26:15 changed by philliptemple@yahoo.co.uk

  • stage changed from Accepted to Ready for checkin.

Change line 10 in django/db/backends/mysql/creation.py from:

'AutoField':         'integer AUTO_INCREMENT',

To:

'AutoField':         'integer UNSIGNED AUTO_INCREMENT',

In lines 709-713 of django/db/models/fields/related.py it casts PositiveIntegerField? and SmallPositiveIntegerField?, as well as AutoField?, to IntegerField?().db_type(). This makes me assume we do not need to make any changes by changing AutoField? to UNSIGNED matching PositiveIntegerField? which is already 'integer UNSIGNED'.

Phillip.


Add/Change #56 (MySQL id columns should be UNSIGNED)




Change Properties
Action