[Django] #32234: Add warning when multiple-column primary keys are found when using inspectdb

13 views
Skip to first unread message

Django

unread,
Dec 1, 2020, 12:46:18 AM12/1/20
to django-...@googlegroups.com
#32234: Add warning when multiple-column primary keys are found when using
inspectdb
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/32234>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 1, 2020, 5:15:45 AM12/1/20
to django-...@googlegroups.com
#32234: Add warning when multiple-column primary keys are found when using
inspectdb
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Damien
Type: New feature | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => assigned
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* easy: 1 => 0
* owner: nobody => Damien
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

`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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:1>

Django

unread,
Dec 1, 2020, 5:21:18 AM12/1/20
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.

-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Damien
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Management | Version: 3.1
commands) |

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: New feature => Cleanup/optimization
* component: Database layer (models, ORM) => Core (Management commands)


--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:2>

Django

unread,
Dec 1, 2020, 5:52:25 AM12/1/20
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Damien
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Damien:

Old description:

> 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

New description:

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

[https://github.com/django/django/pull/13736 PR]

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:3>

Django

unread,
Dec 1, 2020, 12:15:41 PM12/1/20
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Damien
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Damien):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:4>

Django

unread,
Dec 5, 2021, 9:47:14 PM12/5/21
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Damien
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ad Timmering):

* cc: Ad Timmering (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:5>

Django

unread,
May 4, 2022, 1:49:06 AM5/4/22
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: assigned

Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anvesh Mishra):

* owner: Damien => Anvesh Mishra


--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:6>

Django

unread,
May 15, 2022, 10:50:52 AM5/15/22
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: assigned
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Anvesh Mishra):

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 any of the introspection
methods 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:7>

Django

unread,
May 23, 2022, 6:42:26 PM5/23/22
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: assigned
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Anvesh Mishra):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:8>

Django

unread,
May 24, 2022, 4:01:07 AM5/24/22
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: assigned
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:9>

Django

unread,
Jun 1, 2022, 2:42:15 AM6/1/22
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: assigned
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
* needs_tests: 1 => 0
* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:10>

Django

unread,
Jun 1, 2022, 4:11:19 AM6/1/22
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: closed

Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"295249c901e13ec1703ada5c414cd97aba72f3e9" 295249c]:
{{{
#!CommitTicketReference repository=""
revision="295249c901e13ec1703ada5c414cd97aba72f3e9"
Fixed #32234 -- Made inspectdb inform about composite primary keys.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:11>

Django

unread,
Jun 1, 2022, 1:11:07 PM6/1/22
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: closed
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"9a3b7e5e2be751d28b8782ad23a63e1c75f27e24" 9a3b7e5e]:
{{{
#!CommitTicketReference repository=""
revision="9a3b7e5e2be751d28b8782ad23a63e1c75f27e24"
Refs #32234 -- Removed hardcoded IntegerField in inspectdb test.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:12>

Django

unread,
Apr 30, 2025, 9:52:00 AMApr 30
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: closed
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by nessita <124304+nessita@…>):

In [changeset:"4c75858135589f3a00e32eb4d476074536371a32" 4c758581]:
{{{#!CommitTicketReference repository=""
revision="4c75858135589f3a00e32eb4d476074536371a32"
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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:13>

Django

unread,
Apr 30, 2025, 9:54:51 AMApr 30
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: closed
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Natalia <124304+nessita@…>):

In [changeset:"5d03c71b7a2256e776f134a7844c95f0f8f06c6d" 5d03c71b]:
{{{#!CommitTicketReference repository=""
revision="5d03c71b7a2256e776f134a7844c95f0f8f06c6d"
[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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:14>

Django

unread,
May 6, 2025, 2:21:06 AMMay 6
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: closed
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by GitHub <noreply@…>):

In [changeset:"dd133054cb98f77577c06d7ef1f2391a865784bc" dd133054]:
{{{#!CommitTicketReference repository=""
revision="dd133054cb98f77577c06d7ef1f2391a865784bc"
Refs #36052, #32234 -- Fixed inspectdb tests for CompositePrimaryKey on
Oracle.

Tests regression in 4c75858135589f3a00e32eb4d476074536371a32.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:15>

Django

unread,
May 6, 2025, 2:22:15 AMMay 6
to django-...@googlegroups.com
#32234: inspectdb should inform about composite keys.
-------------------------------------+-------------------------------------
Reporter: Damien | Owner: Anvesh
Type: | Mishra
Cleanup/optimization | Status: closed
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"44bda7a6740b60eb72b59dc49a4c7f9a2816cdbf" 44bda7a6]:
{{{#!CommitTicketReference repository=""
revision="44bda7a6740b60eb72b59dc49a4c7f9a2816cdbf"
[5.2.x] Refs #36052, #32234 -- Fixed inspectdb tests for
CompositePrimaryKey on Oracle.

Tests regression in 4c75858135589f3a00e32eb4d476074536371a32.
Backport of dd133054cb98f77577c06d7ef1f2391a865784bc from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32234#comment:16>
Reply all
Reply to author
Forward
0 new messages