#33197: Providing prior implicit field name to db_column should be a noop
------------------------------------------------+------------------------
               Reporter:  Jacob Walls           |          Owner:  nobody
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  Migrations            |        Version:  dev
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 Similar to #31826, I would expect no migration changes detected when a
 `db_column` is added that matches the implicit field name. I tested with
 and without renaming the field on SQLite and MySQL 5.7.31. I'm not
 familiar enough with the review of #31826 to know whether these are
 distinct cases versus if it should be reopened.

 {{{
 class Apple(models.Model):
     core = models.BooleanField()
 }}}

 {{{
 class Apple(models.Model):
     core_renamed = models.BooleanField(db_column='core')
 }}}
 {{{
 Was apple.core renamed to apple.core_renamed (a BooleanField)? [y/N] y
 Migrations for 'renamez':
   renamez/migrations/0002_rename_core_apple_core_renamed_and_more.py
     - Rename field core on apple to core_renamed
     - Alter field core_renamed on apple
 }}}

 `python manage.py sqlmigrate renamez 0002` showing unnecessary SQL:
 {{{
 BEGIN;
 --
 -- Rename field core on apple to core_renamed
 --
 ALTER TABLE "renamez_apple" RENAME COLUMN "core" TO "core_renamed";
 --
 -- Alter field core_renamed on apple
 --
 ALTER TABLE "renamez_apple" RENAME COLUMN "core_renamed" TO "core";
 COMMIT;
 }}}

 Without renaming the field, follow the same flow and get an `AlterField`
 migration without SQL:

 {{{
 BEGIN;
 --
 -- Alter field core on apple
 --
 COMMIT;
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33197>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/058.e657feab62c8ffb09487130ecea79a8b%40djangoproject.com.

Reply via email to