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