#30867: Old indexes should be dropped after new ones are created.
------------------------------------------------+------------------------
               Reporter:  Simon Charette        |          Owner:  nobody
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  Migrations            |        Version:  master
               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                     |
------------------------------------------------+------------------------
 When adding `unique=True` to a field previously `index=True` field or
 vice-versa the old index is dropped before the new one is added.

 This is not a big issue on backends that support transactional DDL but it
 is on ones that don't because in between the execution of the two
 statements the column is not indexed.

 For example given the following model

 {{{#!python
 class Author(models.Model):
     name = models.CharField(max_length=50, db_index=True)
 }}}

 Altering `name` to `models.CharField(max_length=50, unique=True)` will
 generate the following SQL on MySQL

 {{{#!sql
 DROP INDEX `author_name_idx` ON `author`;
 -- Until the following statement completes the name field is not indexed
 at all.
 -- This can take a while on large tables.
 ALTER TABLE `author` ADD CONSTRAINT `author_name_uniq` UNIQUE (`name`);
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30867>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.099fe91c28b50070f0fef6928c0fe9ec%40djangoproject.com.

Reply via email to