Opened 4 years ago
Closed 4 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
AutoFieldpk - model (also with
AutoFieldpk) related toUserviaManyToManyField
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 , 4 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
follow-up: 3 comment:2 by , 4 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
comment:3 by , 4 years ago
| Keywords: | oracle added |
|---|---|
| Resolution: | duplicate |
| Status: | closed → new |
| Summary: | DROP of foreign key constraints in through model when related models migrate to BigAutoField pk → Foreign key constraint in m2m tables is not recreated when altering type of referenced primary key on Oracle. |
| Triage Stage: | Unreviewed → Accepted |
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 , 4 years ago
| Has patch: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:5 by , 4 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Duplicate of #32743 fixed in Django 4.0+, see 3d9040a50b160f8b4bb580e09f4120d4979fe29e.