Opened 5 years ago

Closed 3 years ago

Last modified 2 months ago

#32234 closed Cleanup/optimization (fixed)

inspectdb should inform about composite keys.

Reported by: Damien Owned by: Anvesh Mishra
Component: Core (Management commands) Version: 3.1
Severity: Normal Keywords:
Cc: Ad Timmering 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 Damien)

Since django does not support multiple multiple-column primary keys, there should be a warning that the inspectdb result does not match exactly the database

PR

Change History (16)

comment:1 by Mariusz Felisiak, 5 years ago

Easy pickings: unset
Has patch: set
Needs tests: set
Owner: changed from nobody to Damien
Patch needs improvement: set
Status: newassigned
Triage Stage: UnreviewedAccepted

inspectdb is meant as a shortcut, not as definitive model generation. I would rather add a comment to the field's notes like we do in other cases. Raising a warning can be really annoying when you try to inspect a legacy database.

comment:2 by Mariusz Felisiak, 5 years ago

Component: Database layer (models, ORM)Core (Management commands)
Summary: Add warning when multiple-column primary keys are found when using inspectdbinspectdb should inform about composite keys.
Type: New featureCleanup/optimization

comment:3 by Damien, 5 years ago

Description: modified (diff)

comment:4 by Damien, 5 years ago

Updated the PR to change the warning to be a comment instead of printing it to stderr

comment:5 by Ad Timmering, 4 years ago

Cc: Ad Timmering added

comment:6 by Anvesh Mishra, 3 years ago

Owner: changed from Damien to Anvesh Mishra

comment:7 by Anvesh Mishra, 3 years ago

I actually found a solution to this in SQLite3 through PRAGMA keyword but since PRAGMA is a SQLite3 specific command so my PR didn't passed the Jenkins tests https://github.com/django/django/pull/15683. If you could provide any suggestions cause if we use get_constraint method to fetch the primary key it only takes the first column as primary key and gives no info if there were other primary-key columns. Also I tried the changes given in PR https://github.com/django/django/pull/13736 but they didn't work.

Last edited 3 years ago by Anvesh Mishra (previous) (diff)

comment:8 by Anvesh Mishra, 3 years ago

Submitted a new PR with all the required changes. https://github.com/django/django/pull/15730

comment:9 by Mariusz Felisiak, 3 years ago

Needs documentation: set

comment:10 by Mariusz Felisiak, 3 years ago

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 295249c:

Fixed #32234 -- Made inspectdb inform about composite primary keys.

comment:12 by GitHub <noreply@…>, 3 years ago

In 9a3b7e5e:

Refs #32234 -- Removed hardcoded IntegerField in inspectdb test.

comment:13 by nessita <124304+nessita@…>, 2 months ago

In 4c758581:

Refs #36052, #32234 -- Removed create_test_table_with_composite_primary_key flag in favor of using CompositePrimaryKey.

Now that Django properly supports creating models with composite primary
keys, the tests should use a CompositePrimaryKey field instead of a
feature flag to inline backend specific SQL for creating a composite PK.

Specifcially, the inspectdb's test_composite_primary_key was adjusted to
use schema editor instead of per-backend raw SQL.

comment:14 by Natalia <124304+nessita@…>, 2 months ago

In 5d03c71b:

[5.2.x] Refs #36052, #32234 -- Removed create_test_table_with_composite_primary_key flag in favor of using CompositePrimaryKey.

Now that Django properly supports creating models with composite primary
keys, the tests should use a CompositePrimaryKey field instead of a
feature flag to inline backend specific SQL for creating a composite PK.

Specifcially, the inspectdb's test_composite_primary_key was adjusted to
use schema editor instead of per-backend raw SQL.

Backport of 4c75858135589f3a00e32eb4d476074536371a32 from main.

comment:15 by GitHub <noreply@…>, 2 months ago

In dd133054:

Refs #36052, #32234 -- Fixed inspectdb tests for CompositePrimaryKey on Oracle.

Tests regression in 4c75858135589f3a00e32eb4d476074536371a32.

comment:16 by Mariusz Felisiak <felisiak.mariusz@…>, 2 months ago

In 44bda7a6:

[5.2.x] Refs #36052, #32234 -- Fixed inspectdb tests for CompositePrimaryKey on Oracle.

Tests regression in 4c75858135589f3a00e32eb4d476074536371a32.
Backport of dd133054cb98f77577c06d7ef1f2391a865784bc from main

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