Opened 3 months ago

Closed 3 months ago

#33057 closed Bug (fixed)

Foreign key constraint in m2m tables is not recreated when altering type of referenced primary key on Oracle.

Reported by: Fabio Sangiovanni Owned by: Mariusz Felisiak
Component: Migrations Version: 3.2
Severity: Normal Keywords: oracle
Cc: 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

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

Change History (6)

comment:1 Changed 3 months ago by Mariusz Felisiak

Resolution: duplicate
Status: newclosed

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

comment:2 Changed 3 months ago 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

comment:3 in reply to:  2 Changed 3 months ago by Mariusz Felisiak

Keywords: oracle added
Resolution: duplicate
Status: closednew
Summary: DROP of foreign key constraints in through model when related models migrate to BigAutoField pkForeign key constraint in m2m tables is not recreated when altering type of referenced primary key on Oracle.
Triage Stage: UnreviewedAccepted

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

comment:4 Changed 3 months ago by Mariusz Felisiak

Has patch: set
Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:5 Changed 3 months ago by Carlton Gibson

Triage Stage: AcceptedReady for checkin

comment:6 Changed 3 months ago by GitHub <noreply@…>

Resolution: fixed
Status: assignedclosed

In 1eb3f500:

Fixed #33057 -- Fixed recreation of foreign key constraints in m2m tables when altering type of referenced primary key on Oracle.

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