Ticket #478 (assigned defect)

Opened 5 years ago

Last modified 4 years ago

db.delete_index() doesn't introspect the database to get the name of index, fails with django 1.2

Reported by: gciotta@… Owned by: andrew
Priority: major Milestone: 1.0
Component: databaseapi Version: mercurial
Keywords: Cc:


South uses django < 1.2 conventions to work out names of indexes in db.delete_indexes(), thus failing to get the right indexes with django 1.2. Ideally, it should rely on db introspection instead.

I'm seeing this on mysql, django 1.2, south@tip.

Change History

comment:1 Changed 5 years ago by andrew

  • Milestone set to 0.7.2

comment:2 Changed 5 years ago by andrew

  • Status changed from new to assigned

comment:3 Changed 5 years ago by andrew

  • Milestone changed from 0.7.2 to 1.0

It seems that it's nigh-on impossible to get index names out of databases using introspection easily, since they're not part of the SQL standard. Having to bump this to 1.0 for now.

comment:4 Changed 5 years ago by claude@…

Just FYI, here is the function I use with MySQL:

    def get_index_name(table_name, column_name):
        KEY_NAME_IDX = 2
        COL_NAME_IDX = 4
        saved_dry_run = db.dry_run
        db.dry_run = False
        res = db.execute('SHOW INDEX FROM %s' % db.quote_name(table_name))
        db.dry_run = saved_dry_run
        for row in res:
            if row[COL_NAME_IDX] == column_name:
                return row[KEY_NAME_IDX]
        raise Exception("No index found on column %s from table %s" % (column_name, table_name))

comment:5 Changed 4 years ago by dan@…

Was just referred here from #522 (which is a dupe of this issue). Changed a ForeignKey to a CharField and got django.db.utils.DatabaseError: no such index.

Note: See TracTickets for help on using tickets.