Opened 8 years ago

Closed 8 years ago

#7950 closed (wontfix)

Syncdb generated indices should have a consistent name

Reported by: flytwokites Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


This model:

class User(models.Model):
    live_space = models.IntegerField()
    name = models.CharField(max_length=30, unique=True)
    email = models.EmailField(max_length=50, unique=True)

    class Meta:
        unique_together = ('live_space', 'name')

In mysql, the generated indices have a mysql internal name like 'name_2', 'email_3'.
If i want to maintains indices later, i must known the index name, so i must dump db structure to determine it.
So it's better to generate a consistent name like 'ruby on rails' does.
For example the above model will generate these index names:


Change History (2)

comment:1 Changed 8 years ago by Jeff Anderson

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 8 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

I'm not aware of anything that puts _2 or _3 at the end of an index name - index names (such as the unique indexes in your example) follow the <db_table>_<column name> pattern.

Foreign key references do use a hash of the table names as part of the index name; this appears as a sequence of 10 alphanumerics at the end of an index name. However, this is done specifically because of a limitation of MySQL. These indicies need to have a unique name, but MySQL requires that the names are unique in the first 64 characters. This unique name needs to encompass 4 parts - the column name on the source and target table, and the source and target table names. Given that each of those names can easily exceed 16 characters, we can't just concatenate all the names. We've chosen to use a hash of the table names so that we only have 2 full names competing for 54 characters.

Note: See TracTickets for help on using tickets.
Back to Top