#25817: Unable to rename a field reference in foreign key 'to_field'
---------------------------------+--------------------------------------
     Reporter:  snopoke          |                    Owner:  nobody
         Type:  Uncategorized    |                   Status:  new
    Component:  Migrations       |                  Version:  1.7
     Severity:  Normal           |               Resolution:
     Keywords:  to_field rename  |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Changes (by snopoke):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 As a workaround I was able to use the following custom migration:
 {{{#!python
     operations = [
         migrations.RunSQL(
             'ALTER TABLE form_processor_bar RENAME COLUMN bar_id TO
 external_id',
             'ALTER TABLE form_processor_bar RENAME COLUMN external_id TO
 bar_id',
             state_operations=[
                 migrations.RenameField(
                     model_name='bar',
                     old_name='bar_id',
                     new_name='external_id',
                 ),
                 migrations.AlterField(
                     model_name='bazz',
                     name='bar',
                     field=models.ForeignKey(to='form_processor.Bar',
 to_field=b'external_id'),
                     preserve_default=True,
                 ),
             ]
         )
     ]
 }}}

 However this migration is un-sqaushable:
 {{{
 $ ./manage.py squashmigrations form_processor 0002
 Will squash the following migrations:
  - 0001_initial
  - 0002_rename_bar_id_to_external_id
 Do you wish to proceed? [yN] y
 Optimizing...
 Traceback (most recent call last):
   File "./manage.py", line 73, in <module>
     execute_from_command_line(sys.argv)
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 385, in
 execute_from_command_line
     utility.execute()
   File "/home/skelly/.virtualenvs/hq/local/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/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/core/management/base.py", line 288, in run_from_argv
     self.execute(*args, **options.__dict__)
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/core/management/base.py", line 338, in execute
     output = self.handle(*args, **options)
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/core/management/commands/squashmigrations.py", line 130,
 in handle
     fh.write(writer.as_string())
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/db/migrations/writer.py", line 131, in as_string
     operation_string, operation_imports =
 OperationWriter(operation).serialize()
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/db/migrations/writer.py", line 88, in serialize
     arg_string, arg_imports = MigrationWriter.serialize(arg_value)
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/db/migrations/writer.py", line 263, in serialize
     item_string, item_imports = cls.serialize(item)
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/db/migrations/writer.py", line 350, in serialize
     return cls.serialize_deconstructed(*value.deconstruct())
   File "/home/skelly/.virtualenvs/hq/local/lib/python2.7/site-
 packages/django/db/migrations/writer.py", line 226, in
 serialize_deconstructed
     module, name = path.rsplit(".", 1)
 ValueError: need more than 1 value to unpack
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25817#comment:1>
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/065.67c4e3fff6f7ebdd75c0ea0c5a311e46%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to