Inconsistency in Indexes/Constraints docs

Django docs recommend we move away from using db_index=True & index_together in favor of the indexes Meta option. Likewise, the docs also recommend using the constraints Meta option instead of unique_together . But they do NOT make any such rec for the unique=True field option.

This sticks out a bit since it seem like for everything else the docs say “Hey put all your extra DB objects for your model in the Meta option”. Which would make sense to me, feels like it would be more readable to have them all in one place if nothing else. So why the inconsistency with unique=True ?

I suspect it’s just that an inconsistency. It’s probably worth creating a ticket.

However, as a django dev, I really don’t like how we are telling folks to not use fields because it may be deprecated in the future. I think those recommendations should be based on utility and flexibility of the API. The docs shouldn’t include include mentions of the general feeling of the current developers of Django.

For additional context around a change, it’s often useful to do a git blame to find the commit that added the documentation and then lookup the pull request: Doc'd that Meta.indexes is preferred to Field.db_index. by adamchainz · Pull Request #12716 · django/django · GitHub.

1 Like