django db index 3dtrue

Solutions on MaxInterview for django db index 3dtrue by the best coders in the world

showing results for - "django db index 3dtrue"
Sofie
05 Sep 2016
1When we should use db_index=True in Django?
2
3This is not really django specific; more to do with databases. You add indexes on columns when you want to speed up searches on that column.
4
5Typically, only the primary key is indexed by the database. This means look ups using the primary key are optimized.
6
7If you do a lot of lookups on a secondary column, consider adding an index to that column to speed things up
8I would say you should use db_index=True when you have a field that is unique for more useful lookups.
9
10For example if you a table customers with records of many users they'll each have their own unique user_id. 
11Each user_id would be unique and having to index this field to find that unique user is more often desirable than say their first_name or last_name.
12Actually this is also ok but since they're not unique you will get probably recieve multiple results from your queries and this might not be as useful as using an referencing their id.