[Django] #33057: DROP of foreign key constraints in through model when related models migrate to BigAutoField pk

36 views
Skip to first unread message

Django

unread,
Aug 25, 2021, 6:17:41 PM8/25/21
to django-...@googlegroups.com
#33057: DROP of foreign key constraints in through model when related models
migrate to BigAutoField pk
---------------------------------------------+------------------------
Reporter: Fabio Sangiovanni | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
Hi,

I'm experiencing a weird behaviour migrating from Django 3.1.13 to 3.2.6.

With the following setup:

- Python 3.8.10
- PostgreSQL 11.12
- custom user model with `AutoField` pk
- model (also with `AutoField` pk) related to `User` via `ManyToManyField`

upgrading to Django 3.2.6 with `DEFAULT_AUTO_FIELD =
'django.db.models.BigAutoField'` leads to a DROP of the foreign key
constraints on the (implicit) through model.
The field types on the through model referencing the related models get
upgraded correctly; only FK constraints go missing.

I've setup a small reproducer at https://github.com/sanjioh/django32fk
Interested tables: `app_pet_owner` and Django owned ones involving the
`User` model (`app_user_groups` and `app_user_user_permissions`).

Please let me know if I can be of further help.

Fabio

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

Django

unread,
Aug 26, 2021, 12:34:32 AM8/26/21
to django-...@googlegroups.com
#33057: DROP of foreign key constraints in through model when related models
migrate to BigAutoField pk
-----------------------------------+--------------------------------------

Reporter: Fabio Sangiovanni | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: duplicate

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

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #32743 fixed in Django 4.0+, see
3d9040a50b160f8b4bb580e09f4120d4979fe29e.

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

Django

unread,
Aug 29, 2021, 5:20:40 AM8/29/21
to django-...@googlegroups.com
#33057: DROP of foreign key constraints in through model when related models
migrate to BigAutoField pk
-----------------------------------+--------------------------------------

Reporter: Fabio Sangiovanni | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Fabio Sangiovanni):

Hi Mariusz,

thanks, I somehow missed that searching for previous tickets about this
issue.

I see that the test in the PR detects the problem in case of model
inheritance, while my reproducer triggers it via a ManyToManyField
relation.

Do you think an additional test specifically targeting ManyToManyField
relations would add any value?

Fabio

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

Django

unread,
Aug 30, 2021, 2:24:08 AM8/30/21
to django-...@googlegroups.com
#33057: Foreign key constraint in m2m tables is not recreated when altering type of
referenced primary key on Oracle.
-----------------------------------+------------------------------------

Reporter: Fabio Sangiovanni | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted

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

* keywords: => oracle
* status: closed => new
* resolution: duplicate =>
* stage: Unreviewed => Accepted


Comment:

> Do you think an additional test specifically targeting ManyToManyField
relations would add any value?

Yes it is. I noticed that it doesn't work on Oracle, see
[https://github.com/django/django/pull/14809 PR].

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

Django

unread,
Aug 30, 2021, 2:24:27 AM8/30/21
to django-...@googlegroups.com
#33057: Foreign key constraint in m2m tables is not recreated when altering type of
referenced primary key on Oracle.
-------------------------------------+-------------------------------------
Reporter: Fabio Sangiovanni | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Migrations | Version: 3.2

Severity: Normal | Resolution:
Keywords: oracle | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* owner: nobody => Mariusz Felisiak
* status: new => assigned
* has_patch: 0 => 1


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

Django

unread,
Aug 31, 2021, 5:58:02 AM8/31/21
to django-...@googlegroups.com
#33057: Foreign key constraint in m2m tables is not recreated when altering type of
referenced primary key on Oracle.
-------------------------------------+-------------------------------------
Reporter: Fabio Sangiovanni | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Migrations | Version: 3.2
Severity: Normal | Resolution:
Keywords: oracle | 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 Carlton Gibson):

* stage: Accepted => Ready for checkin


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

Django

unread,
Aug 31, 2021, 7:43:21 AM8/31/21
to django-...@googlegroups.com
#33057: Foreign key constraint in m2m tables is not recreated when altering type of
referenced primary key on Oracle.
-------------------------------------+-------------------------------------
Reporter: Fabio Sangiovanni | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: oracle | 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 GitHub <noreply@…>):

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


Comment:

In [changeset:"1eb3f500a44b08a05868cd8bd85501dd6c7ee6c7" 1eb3f500]:
{{{
#!CommitTicketReference repository=""
revision="1eb3f500a44b08a05868cd8bd85501dd6c7ee6c7"
Fixed #33057 -- Fixed recreation of foreign key constraints in m2m tables


when altering type of referenced primary key on Oracle.
}}}

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

Reply all
Reply to author
Forward
0 new messages