Opened 15 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

Description

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 15 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)

Changed 15 years ago by Bob Thomas

Attachment: primary_fk.diff added

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

comment:1 Changed 15 years ago by Malcolm Tredinnick

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 Changed 15 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:3 Changed 14 years ago by mbee

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 Changed 13 years ago by Gabriel Hurley

Component: django-admin.py inspectdbCore (Management commands)

comment:5 Changed 13 years ago by Luke Plant

Severity: Normal
Type: Bug

comment:6 Changed 12 years ago by Ramiro Morales

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

Changed 12 years ago by David Gouldin

Attachment: 8317_with_tests.diff added

comment:7 Changed 12 years ago by David Gouldin

Owner: changed from nobody to David Gouldin

comment:8 Changed 12 years ago by Julien Phalip

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