Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
Does Django index Autofield / ID keys in PostgreSQL?

Django's docs state that id fields created with AutoField are indexed:

id is indexed by the database and is guaranteed to be unique.

Similarly it applies an index to every FK relationship.

However, in PostgreSQL whilst FKs appear to be indexed, IDs are not. Here's an example:

class TestModelBase(models.Model):
    name = models.CharField(max_length=50)
    fkfield = models.ForeignKey(TestModelFK, blank=True, null=True,
                                on_delete=models.CASCADE)
    m2mfield = models.ManyToManyField(TestModelM2M, related_name='base_m2m')

This model appears to apply the fkfield index, but not the id autofield. From PGAdmin below:

enter image description here

Am I missing something?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

PostgreSQL automatically creates indexes for primary keys. From the 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.

It appears that PGAdmin does not show those indexes. This mailing list thread is the best source I could find.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda