1

Question is: does Django AutoField create db_index on itself? (In docs I didn't find anything about that)

If not, how to do that?

Thanks!

2
  • You can run python manage.py sqlindexes __your_app__ to check the indexes that syncdb will create. Commented Dec 19, 2011 at 0:19
  • I've checked, but there is no index for id field. Commented Dec 19, 2011 at 5:58

1 Answer 1

3

An AutoField must have primary_key=True. A primary key is a unique index.

Sign up to request clarification or add additional context in comments.

4 Comments

By default Django applies id = models.AutoField(primary_key=True) (docs.djangoproject.com/en/dev/topics/db/models/…) however in postgres id fields do not appear to be indexed.
@alias51 see the postgresql docs: Adding a primary key will automatically create a unique B-tree index on the column or group of columns listed in the primary key, and will force the column(s) to be marked NOT NULL.
Thanks. Am I misreading PGAdmin in this question (stackoverflow.com/questions/63164377/…). I.e. does the primary key shown also infer the index? I am confused as I would expect an index to also be shown?
I've left an answer to your question - it appears that PGAdmin does not show the automatic primary key indexes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.