I know that Django automatically generates indexes for foreign keys unless we define the field with db_index=False. I have read it in django doc
But I don't know if it is possible to choose the index name, or how django chooses it.
It's always something like "tablename_xxxxxx".
"xxxxx" are like random characters?
EDITED: I've discovered that "xxxx" is some codification from the model field name, but I still don't know whether we can choose an explicit name
As far as I know, there's no way to choose the name of the index. It's actually dynamically computed and it implies the hash of the table name and the column names.
See for instance the code source here, even though it's for a particular version of Django, I'm not aware of any changes towards a user named index.
Is it possible to choose the index name? yes but there isn't any benefit in doing so.
The first step is to switch off the constraint, then you need to manually add one into the migration in the form of a migrations.RunSQL yes, it's a lot of hard work and totally not worth doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With