#8576: Multiple AutoFields in a model
-------------------------------------+-------------------------------------
     Reporter:  honeyman             |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  multiple autofield   |             Triage Stage:  Design
                                     |  decision needed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Csirmaz Bendegúz):

 * resolution:  wontfix =>
 * status:  closed => new

Comment:

 [https://code.djangoproject.com/ticket/373]
 I'm looking to implement composite primary keys like this:

 {{{
 class Tenant(models.Model):
     pass


 class User(models.Model):
     tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE)
     id = models.SmallAutoField()

     class Meta:
         primary_key = ("tenant_id", "id")
 }}}

 In order to encourage using surrogate keys in composite primary keys, it
 would make a lot of sense to allow non-primary key auto fields.

 We have the following options:
 1. Remove the limitation for databases that support non-primary auto
 fields altogether. We could allow non-primary key auto fields for
 PostgreSQL, for example.
 2. Refactor auto fields so that they are either primary keys OR part of a
 composite primary key. This addresses my use case, but not the others.
 3. Don't use auto fields in composite primary keys. We need an alternative
 in this case.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/8576#comment:10>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f3c36f113-aae666d3-424b-448e-ae40-4c7482b4a846-000000%40eu-central-1.amazonses.com.

Reply via email to