#28824: Allow different Foreign Keys to share same underlying DB column
-------------------------------------+-------------------------------------
               Reporter:  klass-     |          Owner:  nobody
  ivan                               |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |       Keywords:  foreigh key,
               Severity:  Normal     |  db_column,
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 {{{
 class A(Model):
     uid = CharField(unique=True)
     # other fields

 class B(Model):
     uid = CharField(unique=True)
     # other fields

 class C(Model):
    # other fields
    uid  = CharField(unique=False)
    a = ForeignKey(to=A, to_field='uid', db_column='uid', null=True)
    b = ForeignKey(to=B, to_field='uid', db_column='uid', null=True)
 }}}

 Gives an error:

 {{{
 Field 'b' has column name 'uid' that is used by another field.
         HINT: Specify a 'db_column' for the field.
 }}}

 However, ForeignKey field is a ORM relation based on underlying column
 anyway.
 I think it won't break anything if we allow different foreign keys to
 share same underlying column.
 This adds more flexibility and will allow better django "on-boarding"
 process for legacy projects.
 It will be also useful when A or B is proxy model - so we can get
 different proxy objects by different foreign keys referencing same DB row.

 Another example can be found here:
 [https://stackoverflow.com/questions/36911804/django-use-same-column-for-
 two-foreign-keys]

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28824>
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/053.3f32b717c9bb96f922da469f3376ff64%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to