#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------
     Reporter:  Thierry Bastian      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * type:  Uncategorized => Bug
 * component:  Uncategorized => Database layer (models, ORM)


Old description:

> if you have a DB like that
>
> CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);
>
> CREATE TABLE bar ( id serial primary key, other_id int,
> constraint myconst
> FOREIGN KEY(other_id) references foo(other_id)
>                                                                   );
>

> the generated model for the bar table will have the other_id be a FK to
> foo and not foo(other_id).
>
> I'm attaching a potential fix for this. Sorry I had no time for the UTs.

New description:

 if you have a DB like that

 {{{#!sql
 CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);

 CREATE TABLE bar (
     id serial primary key, other_id int,
     constraint myconst
     FOREIGN KEY(other_id) references foo(other_id)
 );
 }}}

 the generated model for the bar table will have the other_id be a FK to
 foo and not foo(other_id).

 I'm attaching a potential fix for this. Sorry I had no time for the UTs.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:3>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.a74d3645d0acc5c12d4115d1455ba9b9%40djangoproject.com.

Reply via email to