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

408
Vistas
SQLAlchemy autoincrement not inserting correctly

I created a customer table with autoincrement id, the problem is after id:5 it inserted 151, 152, 153... how this is happening? is there has any way to fix this?

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

0

There are at least five ways this could happen.

  1. Someone deliberately inserted a row with id=150. This advances the next auto-increment for the table automatically. I.e. auto-increment will not generate a value less than the greatest id in the table.

  2. There were 145 failed INSERTs. By default, InnoDB allocates the next auto-inc value, then tries the INSERT. But it doesn't "undo" the auto-inc if the INSERT fails. So if you have a lot of failed attempts to INSERT rows, for example if they violate other table constraints, then you "lose" auto-inc values. They are allocated, but not used in a row.

  3. Some rows were INSERTed with those values between 6 and 150, then subsequently deleted.

  4. InnoDB spontaneously "skipped" some values. This can happen. Auto-increment must generate unique values, but it is not guaranteed to generate consecutive values.

  5. auto_increment_increment was set to 145 temporarily, then reset to 1, its default value. This doesn't happen by accident, it would have been deliberate.

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