Opened 3 years ago

Closed 3 years 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 by Mariusz Felisiak, 3 years ago

Resolution: duplicate
Status: newclosed

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

comment:2 by Fabio Sangiovanni, 3 years ago

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

in reply to:  2 comment:3 by Mariusz Felisiak, 3 years ago

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 by Mariusz Felisiak, 3 years ago

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

comment:5 by Carlton Gibson, 3 years ago

Triage Stage: AcceptedReady for checkin

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

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