Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#24135 closed Bug (fixed)

migrations.RenameModel does not rename m2m tables

Reported by: Ruben Nielsen Owned by: Tim Graham
Component: Migrations Version: 1.7
Severity: Release blocker Keywords: rename m2m
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

Observe the following models

class Tag(Model):
    content = Charfield(...)

class CustomerModel(Model):
    keywords = ManyToManyField('Tag')

this will generate 3 tables

applabel_customermodel
applabel_tag
applabel_customermodel_keywords

when I try to rename CustomerModel to Customer in a migration, the autogenerated table is not renamed

migration:

operations = [
        migrations.RenameModel('CustomerModel', 'Customer'),
    ]

tables:

applabel_customer
applabel_tag
applabel_customermodel_keywords

This causes my code to fail, since lookups on customer.keywords.all() expect to find the table applabel_customer_keywords, which does not exist.

The error is observed in 1.7.1 and 1.7.2

Change History (7)

comment:1 Changed 6 years ago by Simon Charette

Triage Stage: UnreviewedAccepted

Managed to reproduce against master. Should this block the release of 1.8 alpha?

comment:2 Changed 6 years ago by Tim Graham

Type: UncategorizedBug

I presume it's an existing bug on 1.7 as well, in which case no.

comment:3 Changed 6 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:4 Changed 6 years ago by Tim Graham

Has patch: set

comment:5 Changed 6 years ago by Simon Charette

Triage Stage: AcceptedReady for checkin

comment:6 Changed 6 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 28db4af80a319485c0da724d692e2f8396aa57e3:

Fixed #24135 -- Made RenameModel rename many-to-many tables.

Thanks Simon and Markus for reviews.

comment:7 Changed 6 years ago by Tim Graham <timograham@…>

In 065b2a82f6d7539032e15308351fa5eee95c0cb9:

[1.7.x] Fixed #24135 -- Made RenameModel rename many-to-many tables.

Thanks Simon and Markus for reviews.

Backport of 28db4af80a319485c0da724d692e2f8396aa57e3 from master

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