Opened 7 years ago

Closed 3 years ago

#8317 closed Bug (fixed)

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

Reported by: bthomas Owned by: dgouldin
Component: Core (Management commands) Version: master
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 bthomas 7 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 dgouldin 3 years ago.

Download all attachments as: .zip

Change History (10)

Changed 7 years ago by bthomas

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

comment:1 Changed 7 years ago by mtredinnick

  • milestone set to post-1.0
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 6 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:3 Changed 5 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 4 years ago by gabrielhurley

  • Component changed from django-admin.py inspectdb to Core (Management commands)

comment:5 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to Bug

comment:6 Changed 4 years ago by ramiro

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

Changed 3 years ago by dgouldin

comment:7 Changed 3 years ago by dgouldin

  • Owner changed from nobody to dgouldin

comment:8 Changed 3 years ago by julien

  • Resolution set to fixed
  • Status changed from new to closed

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