Opened 4 weeks ago

Last modified 3 weeks ago

#36803 new Cleanup/optimization

Make AlterField a no-op when ManyToManyField's through.db_table remains the same between renames.

Reported by: Clifford Gama Owned by: Clifford Gama
Component: Migrations Version: 6.0
Severity: Normal Keywords: AlterField, no-op, ManyToManyField
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As suggested by Simon. Similar to f05cc5e3d2ae7663dbd248029bcb74500cf1029f (for db_table on foreign keys) and #31825 for db_columns.

Change History (5)

comment:1 by Jacob Walls, 4 weeks ago

Component: Database layer (models, ORM)Migrations

Thanks. #33197 is another similar fixed ticket.

comment:2 by Jacob Walls, 4 weeks ago

Triage Stage: UnreviewedAccepted

comment:3 by Clifford Gama, 3 weeks ago

Resolution: wontfix
Status: assignedclosed

This is likely not a feasible optimisation with the way the db_table name of an auto-generated through model is backend aware, while the auto detector and makemigrations are backend agnostic. In other words, we have nothing to compare the new db_table with at makemigrations time if the through model is auto-created.

Please reopen if I've missed something.

May be related to #33201.

comment:4 by Clifford Gama, 3 weeks ago

On another note, I just found out that:

class Book(models.Model):
    pass


class Author(models.Model):
    books = models.ManyToManyField(Book, through="AuthorBook")


class AuthorBook(models.Model):
    book = models.ForeignKey(Book, models.CASCADE)
    author = models.ForeignKey(Author, models.CASCADE)

renaming books, to articles without changing anything else results in a RemoveField and AddField, though nothing has changed in the schema

comment:5 by Clifford Gama, 3 weeks ago

Has patch: set
Resolution: wontfix
Status: closednew

We can still optimise when there is an explicit db_table. I opened a PR

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