Opened 5 years ago

Closed 5 years ago

#33187 closed Bug (fixed)

Foreign key to a specific field is not handled in inspectdb

Reported by: Thierry Bastian Owned by: Jordan Bae
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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.

Attachments (1)

handle_fk_to_field.diff​ (1.5 KB ) - added by Thierry Bastian 5 years ago.
simple patch to handle FK to non pk field.

Download all attachments as: .zip

Change History (11)

by Thierry Bastian, 5 years ago

Attachment: handle_fk_to_field.diff​ added

simple patch to handle FK to non pk field.

comment:1 by Thierry Bastian, 5 years ago

Resolution: → invalid
Status: new → closed

it seems I cannot reproduce outside of my own code...

comment:2 by Thierry Bastian, 5 years ago

Resolution: invalid
Status: closed → new

comment:3 by Tim Graham, 5 years ago

Component: Uncategorized → Database layer (models, ORM)
Description: modified (diff)
Summary: Foreign key to a specific field is not handled in inspected → Foreign key to a specific field is not handled in inspectdb
Type: Uncategorized → Bug

comment:4 by Mariusz Felisiak, 5 years ago

Has patch: unset
Triage Stage: Unreviewed → Accepted

comment:5 by Jordan Bae, 5 years ago

Owner: changed from nobody to Jordan Bae
Status: new → assigned

I will check it!

comment:6 by Jacob Walls, 5 years ago

Has patch: set

comment:7 by Mariusz Felisiak, 5 years ago

Patch needs improvement: set

comment:8 by Jordan Bae, 5 years ago

Patch needs improvement: unset

comment:9 by Mariusz Felisiak, 5 years ago

Triage Stage: Accepted → Ready for checkin

comment:10 by Mariusz Felisiak, 5 years ago

Resolution: → fixed
Status: assigned → closed
Note: See TracTickets for help on using tickets.
Back to Top