[Django] #23916: makemigrations does not detect/like model name case changes

35 views
Skip to first unread message

Django

unread,
Nov 25, 2014, 3:56:15 PM11/25/14
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
----------------------------+--------------------
Reporter: scoenye | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
Starting with

{{{
class Evidence(models.Model):
rubrictype = models.ForeignKey('Rubrictype')

class Rubrictype(models.Model):
type_code = models.CharField(max_length=1)
}}}

Make the initial migration:

{{{
$ ./manage.py makemigrations
Migrations for 'as_migrations':
0001_initial.py:
- Create model Evidence
- Create model Rubrictype
- Add field rubrictype to evidence
}}}

Change the name of Rubrictype to RubricType:

{{{
class Evidence(models.Model):
rubrictype = models.ForeignKey('RubricType')

class RubricType(models.Model):
type_code = models.CharField(max_length=1)
}}}

Generate the migration:

{{{
$ ./manage.py makemigrations
Migrations for 'as_migrations':
0002_auto_20141125_1930.py:
- Alter field rubrictype on evidence
}}}

Django does not detect the name change on the RubricType model itself. No
confirmation is requested for the name change and no operation is
generated. The problem is that any subsequent makemigrations run will
generate the same operation ad infinitum:

{{{
$ ./manage.py makemigrations
Migrations for 'as_migrations':
0003_auto_20141125_1930.py:
- Alter field rubrictype on evidence
}}}

If instead the name is changed to RubricXype:

{{{
class Evidence(models.Model):
rubrictype = models.ForeignKey('RubricXype')

class RubricXype(models.Model):
type_code = models.CharField(max_length=1)
}}}

the corresponding migration becomes

{{{
$ ./manage.py makemigrations
Did you rename the as_migrations.Rubrictype model to RubricXype? [y/N] y
Migrations for 'as_migrations':
0002_auto_20141125_1956.py:
- Rename model Rubrictype to RubricXype
}}}

This migration generates a RenameModel operation only and any subsequent
makemigrations runs will properly report "No changes detected". So it
appears the change detector does not pick up on capitalization changes in
model names.

Trying to work around by adding a

{{{
migrations.RenameModel(
old_name='Rubrictype',
new_name='RubricType',
)
}}}

to the auto generated operations results in a ValueError exception when
makemigrations is run again:

{{{
$ ./manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/core/management/commands/makemigrations.py", line 111, in
handle
convert_apps=app_labels or None,
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/db/migrations/autodetector.py", line 42, in changes
changes = self._detect_changes(convert_apps, graph)
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/db/migrations/autodetector.py", line 109, in
_detect_changes
self.old_apps = self.from_state.render(ignore_swappable=True)
File "/home/svencoenye/developer/django_test/lib/python2.7/site-
packages/django/db/migrations/state.py", line 89, in render
model=lookup_model,
ValueError: Lookup failed for model referenced by field
as_migrations.Evidence.rubrictype: as_migrations.RubricType
}}}

The sequence of the operations does not matter. Neither does substituting
the RenameModel operation for the AlterField operation.

(Looking at the next to last entry in the traceback, the autodetector
seems to be looking for the new name in the old_apps state?)

It is possible, however, to go the long way around and use two separate
migrations: Rubrictype -> RubricXype. RubricXype -> RubricType works
without getting the migration state stuck and does not throw an exception.

--
Ticket URL: <https://code.djangoproject.com/ticket/23916>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 25, 2014, 6:58:07 PM11/25/14
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
----------------------------+------------------------------------

Reporter: scoenye | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | 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 timgraham):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:1>

Django

unread,
Nov 26, 2014, 10:03:22 PM11/26/14
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
----------------------------+------------------------------------

Reporter: scoenye | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | 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 MarkusH):

* cc: info+coding@… (added)


Comment:

Thank you for the report. The problem you ran into relates to the fact
that the migration internally don't care about case sensitivity of model
names (`ProjectState.models` has a dictionary whose keys are `(app_label,
model_name)` where the latter is lower cased).

Your work around seems to be valid. I'd need more info to figure out why
adding the RenameModel manually fails.

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:2>

Django

unread,
Dec 15, 2014, 10:22:47 AM12/15/14
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
----------------------------+------------------------------------

Reporter: scoenye | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | 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 scoenye):

Sorry for the delayed response. I did not realize my e-mail address was
missing from the preferences.

Is there anything I can do to provide more info on the RenameModel
failure?

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:3>

Django

unread,
Sep 21, 2015, 2:11:01 PM9/21/15
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
----------------------------+------------------------------------

Reporter: scoenye | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | 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 timgraham):

See #25429 for a probable duplicate (but please check when this is fixed
and reopen it if not).

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:4>

Django

unread,
Jun 13, 2016, 3:31:31 PM6/13/16
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
----------------------------+------------------------------------

Reporter: scoenye | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | 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 timgraham):

#26752 seems to be another symptom (closed as duplicate, but reopen if
not).

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

Django

unread,
Jan 17, 2017, 3:23:22 PM1/17/17
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-----------------------------+------------------------------------
Reporter: Sven Coenye | Owner: nobody

Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | 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 Anton Samarchyan):

This is a duplicate of #27297

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

Django

unread,
Jan 13, 2020, 11:27:02 AM1/13/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

Severity: Normal | 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 Adam (Chainz) Johnson):

* owner: nobody => Adam (Chainz) Johnson
* status: new => assigned
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:7>

Django

unread,
Jan 13, 2020, 3:22:11 PM1/13/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* version: 1.7 => master
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:8>

Django

unread,
Jan 20, 2020, 10:09:41 AM1/20/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Daniel S):

Pardon my ignorance, but does this recent activity mean something is being
done about this bug? I've only just run into it (changed a model name in
casing only and now have infinite migration detection), so I'd be
interested in finding a workaround. Replying to [comment:8 felixxm]:

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

Django

unread,
Jan 20, 2020, 10:29:36 AM1/20/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adam (Chainz) Johnson):

Yes, there's a pull request - see the "Pull Requests" row in the table at
the top describing the issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:10>

Django

unread,
Mar 21, 2020, 8:37:15 PM3/21/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Dustin Harrison):

I hit this issue with Django 2.2.11.

- Renamed several models with a case change only
- Generated a migration with `makemigrations`
- Subsequent migrations would always detect a change.
- Ported Adam's patch to 2.2.12
- `makemigrations` no longer detects changes

There were no conflicts in the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:11>

Django

unread,
Mar 22, 2020, 4:10:38 PM3/22/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | 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 Adam (Chainz) Johnson):

* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:12>

Django

unread,
Mar 25, 2020, 5:40:25 AM3/25/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | 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 felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:13>

Django

unread,
Mar 25, 2020, 6:11:03 AM3/25/20
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-------------------------------------+-------------------------------------
Reporter: Sven Coenye | Owner: Adam
| (Chainz) Johnson
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

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 Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"9e1b6b8a66af4c2197e5b1b41eb9dbb36e4f6502" 9e1b6b8]:
{{{
#!CommitTicketReference repository=""
revision="9e1b6b8a66af4c2197e5b1b41eb9dbb36e4f6502"
Fixed #23916 -- Allowed makemigrations to handle related model name case
changes.

Made autodetector ignore related model name case changes so unnecessary
migrations are not created.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:14>

Django

unread,
Feb 16, 2022, 3:09:53 PM2/16/22
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-----------------------------+---------------------------------------------
Reporter: Sven Coenye | Owner: Adam Johnson
Type: Bug | Status: closed
Component: Migrations | Version: dev

Severity: Normal | Resolution: fixed
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
-----------------------------+---------------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"1e2e1be02bdf0fe4add0d0279dbca1d74ae28ad7" 1e2e1be]:
{{{
#!CommitTicketReference repository=""
revision="1e2e1be02bdf0fe4add0d0279dbca1d74ae28ad7"
Fixed #33515 -- Prevented recreation of migration for ManyToManyField to
lowercased swappable setting.

Thanks Chris Lee for the report.

Regression in 43289707809c814a70f0db38ca4f82f35f43dbfd.

Refs #23916.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:15>

Django

unread,
Feb 16, 2022, 3:11:14 PM2/16/22
to django-...@googlegroups.com
#23916: makemigrations does not detect/like model name case changes
-----------------------------+---------------------------------------------
Reporter: Sven Coenye | Owner: Adam Johnson
Type: Bug | Status: closed
Component: Migrations | Version: dev
Severity: Normal | Resolution: fixed
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
-----------------------------+---------------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"760b7e7f4f62eafdc79a2188d2a7739abaa6ca8b" 760b7e7f]:
{{{
#!CommitTicketReference repository=""
revision="760b7e7f4f62eafdc79a2188d2a7739abaa6ca8b"
[4.0.x] Fixed #33515 -- Prevented recreation of migration for


ManyToManyField to lowercased swappable setting.

Thanks Chris Lee for the report.

Regression in 43289707809c814a70f0db38ca4f82f35f43dbfd.

Refs #23916.
Backport of 1e2e1be02bdf0fe4add0d0279dbca1d74ae28ad7 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23916#comment:16>

Reply all
Reply to author
Forward
0 new messages