Opened 3 years ago

Closed 3 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 3 years ago.
simple patch to handle FK to non pk field.

Download all attachments as: .zip

Change History (11)

by Thierry Bastian, 3 years ago

Attachment: handle_fk_to_field.diff added

simple patch to handle FK to non pk field.

comment:1 by Thierry Bastian, 3 years ago

Resolution: invalid
Status: newclosed

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

comment:2 by Thierry Bastian, 3 years ago

Resolution: invalid
Status: closednew

comment:3 by Tim Graham, 3 years ago

Component: UncategorizedDatabase layer (models, ORM)
Description: modified (diff)
Summary: Foreign key to a specific field is not handled in inspectedForeign key to a specific field is not handled in inspectdb
Type: UncategorizedBug

comment:4 by Mariusz Felisiak, 3 years ago

Has patch: unset
Triage Stage: UnreviewedAccepted

comment:5 by Jordan Bae, 3 years ago

Owner: changed from nobody to Jordan Bae
Status: newassigned

I will check it!

comment:6 by Jacob Walls, 3 years ago

Has patch: set

comment:7 by Mariusz Felisiak, 3 years ago

Patch needs improvement: set

comment:8 by Jordan Bae, 3 years ago

Patch needs improvement: unset

comment:9 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:10 by Mariusz Felisiak, 3 years ago

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