[Answer]-Why key length needs to be specified when db_index=False?

1👍

It is because unique keyword will automatically generate an index for the field, even if you specify db_index=False.

You should think of it like, unique=True will overwrite db_index=False in this case.

Updated:

If you look at the SQL statement (use sqlmigrate if you’re >= Django 1.7), you can see it clearly that unique=True overwrites db_index=False:

... "foo" text NOT NULL UNIQUE

So, if you do not want to have the index at all, you need to drop unique=True altogether.

Hope this helps.

👤Anzel

Leave a comment