---
title: "Acuan index model"
version: 2.1
locale: id
source: https://docs.djangoproject.com/id/2.1/ref/models/indexes/
canonical: https://djangodocs.dev/id/2.1/ref/models/indexes/
---
# Acuan index model

Index classes ease creating database indexes. They can be added using the
[`Meta.indexes`](/id/2.1/ref/models/options/#django.db.models.Options.indexes) option. This document
explains the API references of [`Index`](#django.db.models.Index) which includes the [index
options](#index-options).

> **Mengacu pengindeksan siap-pakai**
>
> Pengindeksan ditentukan dalam `django.db.models.indexes`, tetapi untuk kenyamanan mereka diimpor kedalam [`django.db.models`](/id/2.1/topics/db/models/#module-django.db.models). Kebiasaan standar untuk digunakan `from django.db import models` dan mengacu ke pengindeksan sebagai `models.<IndexClass>`.

## Pilihan `Index`

#### `class Index(fields=(), name=None, db_tablespace=None)`

Membuat sebuah index (B-tree) dalam basisdata.

### `fields`

#### `Index.fields`

Sebuah list atau tuple dari nama dari bidang-bidang dimana indeks diharapkan.

By default, indexes are created with an ascending order for each column. To
define an index with a descending order for a column, add a hyphen before the
field's name.

For example `Index(fields=['headline', '-pub_date'])` would create SQL with
`(headline, pub_date DESC)`. Index ordering isn't supported on MySQL. In that
case, a descending index is created as a normal index.

> **Changed in Django 2.1**
>
> Versi terlama tidak menerima sebuah tuple.

### `name`

#### `Index.name`

The name of the index. If `name` isn't provided Django will auto-generate a
name. For compatibility with different databases, index names cannot be longer
than 30 characters and shouldn't start with a number (0-9) or underscore (\_).

### `db_tablespace`

#### `Index.db_tablespace`

> **New in Django 2.0**

The name of the [database tablespace](/id/2.1/topics/db/tablespaces/) to use for
this index. For single field indexes, if `db_tablespace` isn't provided, the
index is created in the `db_tablespace` of the field.

If [`Field.db_tablespace`](/id/2.1/ref/models/fields/#django.db.models.Field.db_tablespace) isn't specified (or if the index uses multiple
fields), the index is created in tablespace specified in the
[`db_tablespace`](/id/2.1/ref/models/options/#django.db.models.Options.db_tablespace) option inside the model's
`class Meta`. If neither of those tablespaces are set, the index is created
in the same tablespace as the table.

> **See also**
>
> Untuk daftar dari index khusus-PostgreSQL, lihat [`django.contrib.postgres.indexes`](/id/2.1/ref/contrib/postgres/indexes/#module-django.contrib.postgres.indexes).
