Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23069 closed Bug (invalid)

Can't rename model with ManyToMany relation

Reported by: Jeroen Dekkers Owned by: nobody
Component: Migrations Version: 1.7-rc-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Given the following models:

class Model1(models.Model):
    field = models.CharField(max_length=10)
    many = models.ManyToManyField('Model2')


class Model2(models.Model):
    field = models.CharField(max_length=10)

If I rename either Model1 or Model2 to Model3 I get the following error when running makemigrations:

CommandError: System check identified some issues:

ERRORS:
myapp1.Model3.many: (fields.E304) Reverse accessor for 'Model3.many' clashes with reverse accessor for 'Model3.field'.
        HINT: Add or change a related_name argument to the definition for 'Model3.many' or 'Model3.field'.
myapp2.Model3.field: (fields.E304) Reverse accessor for 'Model3.field' clashes with reverse accessor for 'Model3.many'.
        HINT: Add or change a related_name argument to the definition for 'Model3.field' or 'Model3.many'.

Change History (4)

comment:1 by Ramiro Morales, 10 years ago

From the system check output it seems you have another application which also has a model named 'Model3'?

comment:2 by Ramiro Morales, 10 years ago

Resolution: needsinfo
Status: newclosed

I've just tested this using branch stable/1.7.x as of now

  1. I created an initial migration with models Model1 and Model2 as reported. Applied it.

Then I've

  1. renamed Model1->Model3
  1. ran makemigrations and migrate
  1. renamed Model3->Model1
  1. ran makemigrations and migrate
  1. renamed Model2->Model3
  1. ran makemigrations and migrate
  1. renamed Model3->Model2
  1. ran makemigrations and migrate

For a total of 5 automatic migrations created for the app.

Didn't see the errors reported.

Note 1: execution of makemigrations always asked confirmation about the model rename I as performing, which it detected correctly.
Note 2: execution of migrate always asked if I wanted to delete the stale content type for the model I was renaming from.

Pleas reope if you can provide more details on how to reproduce the issue you are seeing.

comment:3 by Jeroen Dekkers, 10 years ago

You are right, I didn't pay enough attention when trying to make a reproducible bug report and forgot I still had a "myapp2" from creating another bug report. I actually had a problem with renaming a model in a manytomany relation a few days before I reported the bug, but didn't have the time to make a proper bug report then.

I have been trying to do reproduce the error again, but it seems to indeed all work fine, so either I was doing something wrong or the problem has been fixed in the meantime.

Sorry for the noise.

comment:4 by Tim Graham, 10 years ago

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