Hi all,

At the Django under the hood sprint I picked up #23577 
<https://code.djangoproject.com/ticket/23577> which says, in the general 
case: 

   1. For any database object when django creates an associated index
   2. If you rename that object
   3. Then re-create another with the original's name
   4. You get a collision in the name of the associated index

This applies in the simplest case to renaming any field with db_index=True, 
then re-creating another in it's place. But also renaming a model 
containing a ForeignKey or indexed field, then re-creating the model. (All 
via db migrations)

The instinctive desire is to rename indexes when renaming objects whose 
name was used in the index creation. But speaking to Andrew Godwin, he 
feels this would be quite a large challenge, across all our supported 
backends.

The alternative he suggested was to add a random element to all index names 
the schema editor creates. This post is seeking to validate that proposal.

Note: it's only the names of indexes at issue here, databases keep 
everything pointing at the right objects. There's also no issue with Django 
needing to access an index via a predictable name, as there's introspection 
which grabs indexes according to the objects they work on.

Bonus question: given the scenario above, can we come up with a source of 
index naming that differs after the "parent" object is renamed/re-created, 
but which remains deterministic? Something like pulling in a hash of the 
whole app model state. Unfortunately, as we aim to output migrations to 
sql, we can't have any introspection at migration application time, so for 
example no checking for name collisions.

Cheers,
Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/99246d04-b205-42a6-a389-a0370bea3cd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to