Opened 16 years ago

Closed 12 years ago

#8317 closed Bug (fixed)

inspectdb does not set primary_key=True or unique=True on foreign keys

Reported by: Bob Thomas Owned by: David Gouldin
Component: Core (Management commands) Version: dev
Severity: Normal Keywords: inspectdb
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


The inspectdb command will not set primary_key=True or unique=True on ForeignKey fields when the column is also a primary key.

Attachments (2)

primary_fk.diff (1.6 KB ) - added by Bob Thomas 16 years ago.
Move the code that sets primary_key=True above the check for foreign keys
8317_with_tests.diff (3.0 KB ) - added by David Gouldin 12 years ago.

Download all attachments as: .zip

Change History (10)

by Bob Thomas, 16 years ago

Attachment: primary_fk.diff added

Move the code that sets primary_key=True above the check for foreign keys

comment:1 by Malcolm Tredinnick, 16 years ago

milestone: post-1.0
Needs tests: set
Triage Stage: UnreviewedAccepted

Jeremy Dunck was looking into writing some tests for inspectdb as part of #7285 and #6935. This change should add to those tests when it's landed. It seems like a reasonable change, but it can wait until we have time to check it's not going to break anything else (for which tests will be very handy).

comment:2 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:3 by mbee, 14 years ago

I got the same error last week with Django 1.1.1 and I end up with the same patch. Hopefully I found this ticket before submitting mine!
Could you have a look to this patch again? #7285 and #6935 have been closed a long time ago.

comment:4 by Gabriel Hurley, 13 years ago

Component: inspectdbCore (Management commands)

comment:5 by Luke Plant, 13 years ago

Severity: Normal
Type: Bug

comment:6 by Ramiro Morales, 13 years ago

Easy pickings: unset
Keywords: inspectdb added
UI/UX: unset

by David Gouldin, 12 years ago

Attachment: 8317_with_tests.diff added

comment:7 by David Gouldin, 12 years ago

Owner: changed from nobody to David Gouldin

comment:8 by Julien Phalip, 12 years ago

Resolution: fixed
Status: newclosed

In [17451]:

Fixed #8317 -- Corrected the inspectdb management command to properly set primary_key=True and unique=True on foreign keys. Thanks to bthomas for the report and patch, and to David Gouldin for the tests.

Note: See TracTickets for help on using tickets.
Back to Top