[Django] #36800: Issue with ManyToManyField renaming

6 views
Skip to first unread message

Django

unread,
Dec 15, 2025, 5:27:49 AM (yesterday) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 6.0 | 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
-------------------------------------+-------------------------------------
Since Django 6.0, using Postgres 16 database, when a ManyToManyField is
renamed, it cannot be access anymore.


Models before field renaming:
{{{
from django.db import models


class Book(models.Model):
title = models.CharField(max_length=200)


class Author(models.Model):
name = models.CharField()
books = models.ManyToManyField(Book)

}}}

In Postgres database I have the following table for the m2m relation
**my_app_author_books**.



I then renamed the m2m field "books" to "volumes":


{{{
from django.db import models


class Book(models.Model):
title = models.CharField(max_length=200)


class Author(models.Model):
name = models.CharField()
volumes = models.ManyToManyField(Book)
}}}

This generates the following migration:


{{{
# Generated by Django 6.0 on 2025-12-15 10:04

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('my_app', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='author',
old_name='books',
new_name='volumes',
),
]
}}}

In Postgres database I still have the following table for the m2m relation
**my_app_author_books**. The table was not renamed to
**my_app_author_volumes** which was the case in Django 5.2.

Maybe this is a new behaviour but when I get all instances of volumes, in
shell_plus:

{{{author_instance.volumes.all()}}}
gives
{{{
ProgrammingError: relation "my_app_author_volumes" does not exist
LINE 1: ...y_app_book"."title" FROM "my_app_book" INNER JOIN "my_app_au...
}}}

Migrations were played

**python manage.py showmigrations** gives:
{{{
my_app
[X] 0001_initial
[X] 0002_rename_books_author_volumes
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36800>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 15, 2025, 9:34:41 AM (yesterday) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution:
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 karyon):

I saw this too. sqlmigrate in 5.2 outputs something like
{{{
-- Rename field degrees on course to programs
-- Rename field books on author to volumes
--
ALTER TABLE "my_app_author_books" RENAME TO "my_app_author_volumes";

}}}

With 6.0, the ALTER TABLE line is replaced by {{{-- (no-op)}}}.


Adding this to the migration works around it:
{{{
migrations.RunSQL(
sql='ALTER TABLE "my_app_author_books" RENAME TO
"my_app_author_volumes";',
reverse_sql='ALTER TABLE "my_app_author_volumes" RENAME TO
"my_app_author_books";',
),
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36800#comment:1>

Django

unread,
Dec 15, 2025, 9:58:15 AM (yesterday) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* owner: (none) => Clifford Gama
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
* status: new => assigned

Comment:

Thanks for the report! I haven't bisected yet but I tested against both
5.2. and 6.0 and reproduced the issue in the latter.
--
Ticket URL: <https://code.djangoproject.com/ticket/36800#comment:2>

Django

unread,
Dec 15, 2025, 10:05:03 AM (yesterday) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Clifford Gama):

Regression in f9a44cc0fac653f8e0c2ab1cdfb12b2cc5c63fc2.
--
Ticket URL: <https://code.djangoproject.com/ticket/36800#comment:3>

Django

unread,
Dec 15, 2025, 10:15:10 AM (yesterday) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by ericmuijs):

I think I'm also having the same issue. I had a many to many field and a
test fixture. With django 6 im unable to load the fixture: error is that
the table does not exists. Difference in naming is the cause:

Naming of many to many table
1. Dev Database (tables created by django 5) :
base_vergunningproductgroep_producten (plural)
2. Test database (tables created by django 6) :
base_vergunningproductgroep_product

{{{#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class VergunningProductGroep(TenantModel):
vergunning = models.ForeignKey(Vergunning, on_delete=models.CASCADE,
related_name='vergunningproducten')
producten = models.ManyToManyField(Product,
related_name='vergunningproductgroepen')
}}}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36800#comment:4>

Django

unread,
Dec 15, 2025, 10:25:48 AM (yesterday) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* cc: Ryan P Kilby, Simon Charette (added)

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

Django

unread,
Dec 15, 2025, 4:44:49 PM (22 hours ago) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* has_patch: 0 => 1

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

Django

unread,
Dec 15, 2025, 5:04:39 PM (21 hours ago) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* cc: Simon Charette (removed)

Comment:

Not sure why I was pinged here and on Discord if there was already a
patch, it gave me the impression there was an urgent need for me to look
at this.

The proposed solution looks right to me albeit we might want to adjust the
comment about no field alteration needed to take place if the name change
as that's no true for many-to-many fields and likely what made us miss
this in the first place.

Here's [https://github.com/django/django/pull/20412/ where I got during my
plane trip].
--
Ticket URL: <https://code.djangoproject.com/ticket/36800#comment:7>

Django

unread,
Dec 15, 2025, 9:25:50 PM (17 hours ago) Dec 15
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Pravin M D):

Thanks for the report! I'm also having the same issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/36800#comment:8>

Django

unread,
8:33 AM (6 hours ago) 8:33 AM
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | 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 Jacob Walls):

* stage: Accepted => Ready for checkin

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

Django

unread,
2:12 PM (9 minutes ago) 2:12 PM
to django-...@googlegroups.com
#36800: Issue with ManyToManyField renaming
-------------------------------------+-------------------------------------
Reporter: Josik | Owner: Clifford
| Gama
Type: Bug | Status: assigned
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

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

Comment:

An Oracle failure to check.
--
Ticket URL: <https://code.djangoproject.com/ticket/36800#comment:10>
Reply all
Reply to author
Forward
0 new messages