#56: Primary key columns should be UNSIGNED
-------------------------------------+-------------------------------------
     Reporter:  Manuzhai <mail@…>    |                    Owner:
                                     |  giuliettamasina
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  mysql                |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by giuliettamasina):

 * owner:  christopherdcunha => giuliettamasina
 * cc: markus.magnuson@… (added)


Comment:

 I've rewritten pzinovkin's patch based on the
 [https://github.com/django/django/pull/1156 previous pull request] from
 gcc:

 https://github.com/alimony/django/compare/master...alimony:unsigned-
 primary-keys

 Did not open a pull request yet as it's not ready, most importantly the
 tests are failing:

 As far as I can see, the new `test_can_use_large_primary_keys` test can
 never have passed on postgres. There is no concept of unsigned in
 postgres, meaning a primary key bigger than 2147483648 only fits in a
 bigint/bigserial. The latter is used for the `AutoField` itself in this
 patch, but as someone pointed out, having a foreign key reference such
 large primary key fails.

 The updated `AutoField` in the patch
 [https://github.com/alimony/django/compare/master...alimony:unsigned-
 primary-keys#diff-bf776a3b8e5dbfac2432015825ef8afeR953 determines the
 field type] of a foreign key that references itself like this:

 {{{
 #!python
 def rel_db_type(self, connection):
     db_type = 'PositiveIntegerField' if self.unsigned else 'IntegerField'
     return self._internal_to_db_type(db_type, connection)
 }}}

 But both `PositiveIntegerField` and `IntegerField` resolve to `integer` in
 the case of postgres.

 Some ways it can ever do anything else, that I can think of now, are:

 1. Set `related_fields_match_type` to `True` for postgres.
 2. Make `PositiveIntegerField` mean a `bigint` for postgres.
 3. Make the `rel_db_type` method of the new `AutoField` do some special
 treatment to return e.g. `BigIntegerField` for postgres if `self.unsigned`
 is true.

 (The first two are of course out of the question.)

 I want to write proper tests for this patch to make sure everything
 behaves on every database, but I guess there needs to be some sort of
 consensus first on how to solve the above. And people with far more
 knowledge on Django than me will have to reach that consensus :)

--
Ticket URL: <https://code.djangoproject.com/ticket/56#comment:42>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/085.df5236d1e1a7a63ea516a492e1ac1a8f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to