#24260: Add migration support for logical field renames -----------------------------+------------------------------------ Reporter: pennersr | Owner: nobody Type: New feature | 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 MarkusH): You should get it working with {{{#!python operations = [ migrations.AlterField( model_name='foo', name='foo_id', field=models.AutoField(db_column='foo_id', primary_key=True, serialize=False), ), migrations.RenameField( model_name='foo', old_name='foo_id', new_name='id', ), ] }}} This can be semi-automated by first ensuring the field arguments are explicitly set for `foo_id` (`foo_id = models.AutoField(primary_key=True, db_column='foo_id')`, then running makemigrations followed by a rename (`id = models.AutoField(primary_key=True, db_column='foo_id')` and another makemigrations (the latter will ask if `foo.foo_id` is being renamed to `foo.id`). I don't, however, see a way how Django could automatically detect these changes in a single run, given that we have to check for renamed fields first: https://github.com/django/django/blob/master/django/db/migrations/autodetector.py#L183-L186 . After all, we will end up with two operations. -- Ticket URL: <https://code.djangoproject.com/ticket/24260#comment:4> 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/066.b9d95bf7b4c592fd2b0699e0e8fda09a%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.