#25429: M2M migration is inconsistently case-sensitive
-------------------------+-------------------------------------------------
     Reporter:  staab    |      Owner:  nobody
         Type:  Bug      |     Status:  new
    Component:           |    Version:  1.8
  Migrations             |   Keywords:  case sensitivity migrations
     Severity:  Normal   |  manytomany
 Triage Stage:           |  Has patch:  0
  Unreviewed             |
Easy pickings:  0        |      UI/UX:  0
-------------------------+-------------------------------------------------
 When I rename a model and its uses to the same name with letters in
 different cases (e.g., "TestThing" > "Testthing") in ManyToManyForeign
 keys pointing to it, I get odd behavior in migrations. At times, the
 migration gets stuck, and tries to run the same change multiple times
 (since the relevant information is lowercase, it can't tell the difference
 between the old state and the new state), and other times, I get an error
 similar to the following:


 {{{
 Applying m2mtestcase.0003_auto_20150918_1747...Traceback (most recent call
 last):
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/core/management/__init__.py", line 338, in
 execute_from_command_line
     utility.execute()
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/core/management/__init__.py", line 330, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/core/management/base.py", line 393, in run_from_argv
     self.execute(*args, **cmd_options)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/core/management/base.py", line 444, in execute
     output = self.handle(*args, **options)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/core/management/commands/migrate.py", line 222, in
 handle
     executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/db/migrations/executor.py", line 110, in migrate
     self.apply_migration(states[migration], migration, fake=fake,
 fake_initial=fake_initial)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/db/migrations/executor.py", line 148, in
 apply_migration
     state = migration.apply(state, schema_editor)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/db/migrations/migration.py", line 115, in apply
     operation.database_forwards(self.app_label, schema_editor, old_state,
 project_state)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/db/migrations/operations/fields.py", line 201, in
 database_forwards
     schema_editor.alter_field(from_model, from_field, to_field)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/db/backends/base/schema.py", line 469, in
 alter_field
     return self._alter_many_to_many(model, old_field, new_field, strict)
   File "/home/jstaab/.virtualenvs/m2mcasesensitivity/local/lib/python2.7
 /site-packages/django/db/backends/sqlite3/schema.py", line 232, in
 _alter_many_to_many
 old_field.rel.through._meta.get_field(old_field.m2m_reverse_field_name()),
 AttributeError: 'ManyToManyField' object has no attribute
 'm2m_reverse_field_name'
 }}}

 Here's a shell script that you can run to create a django app and run
 migrations that will cause this error (it assumes you're using
 virtualenvwrapper and have access to GNU sed. Tweak it as necessary):


 {{{
 mkvirtualenv m2mcasesensitivity
 pip install Django===1.8.4
 django-admin startproject m2mcasesensitivity
 cd m2mcasesensitivity
 ./manage.py startapp m2mtestcase
 sleep 1 # Race condition?
 sed -i 's/INSTALLED_APPS = (/INSTALLED_APPS = ("m2mtestcase",/'
 m2mcasesensitivity/settings.py
 echo "
 from django.db import models

 class FirstProblemModel(models.Model):
     pass


 class SecondProblemModel(models.Model):
     first_things = models.ManyToManyField(FirstProblemModel)
 " > m2mtestcase/models.py
 ./manage.py makemigrations
 ./manage.py migrate
 sed -i 's/ProblemModel/problemmodel/g' m2mtestcase/models.py
 ./manage.py makemigrations
 ./manage.py migrate
 sed -i 's/problemmodel/ProblemModel/g' m2mtestcase/models.py
 ./manage.py makemigrations
 ./manage.py migrate
 }}}

 {{{
 To tear down:
 deactivate
 rmvirtualenv m2mcasesensitivity
 cd ..
 rm -rf m2mcasesensitivity
 }}}

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.d2d156e41f7895bce72dad4642ea7819%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to