Common SQL Errors

MySQL Error 1869: ER_AUTO_INCREMENT_CONFLICT - How to Fix and Prevent

Galaxy Team
August 8, 2025

The query supplies an explicit value that collides with the next AUTO_INCREMENT number, so MySQL aborts the statement to protect primary-key uniqueness.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1869 ER_AUTO_INCREMENT_CONFLICT?

MySQL error ER_AUTO_INCREMENT_CONFLICT occurs when an UPDATE or INSERT supplies a value that clashes with the engine’s next auto increment. Remove or adjust the explicit value, or reseed the AUTO_INCREMENT counter, to resolve the conflict.

Error Highlights

Typical Error Message

ER_AUTO_INCREMENT_CONFLICT

Error Type

Data Integrity Error

Language

MySQL

Symbol

generated values ER_AUTO_INCREMENT_CONFLICT was added in 5.7.2.

Error Code

1869

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1869 ER_AUTO_INCREMENT_CONFLICT?

MySQL raises error 1869 when an UPDATE or INSERT ON DUPLICATE KEY UPDATE statement tries to set an AUTO_INCREMENT column to a value that duplicates the internal counter reserved for the same operation. The engine blocks the change to preserve primary key uniqueness.

The error was introduced in MySQL 5.7.2. Earlier releases could silently overwrite rows, so the new behaviour prevents hard-to-detect data loss during replication, bulk loads or manual maintenance.

What Causes This Error?

The most common trigger is an UPDATE that explicitly changes the primary key to a number equal to the next AUTO_INCREMENT value that MySQL has already picked. The clash surfaces only when the write occurs in the same statement batch.

Cloning data between servers, replaying binlogs and manual key repairs can also introduce conflicting values. Large gaps in AUTO_INCREMENT sequences or parallel sessions with high concurrency increase the odds.

How to Fix ER_AUTO_INCREMENT_CONFLICT

First verify the current AUTO_INCREMENT value with SHOW TABLE STATUS or information_schema tables. If the conflicting value is unneeded, remove it from the UPDATE. If you must keep it, reseed the counter above the highest key.

After adjusting the key or counter, retry the statement. Always test in a transaction or staging database before running on production.

Common Scenarios and Solutions

During replication, ensure the replica uses the same insert order as the primary. If gap handling is different, reseed AUTO_INCREMENT on both nodes to the same upper bound.

During bulk loads, insert data in ascending key order or disable AUTO_INCREMENT updates and let MySQL assign keys, then reseed if necessary.

Best Practices to Avoid This Error

Never hard-code primary key values unless absolutely required. Use placeholders and let MySQL assign keys automatically.

Monitor AUTO_INCREMENT columns with periodic queries, and set alerts when counters near integer limits. Galaxy’s schema browser surfaces current counters so conflicts are caught before deployment.

Related Errors and Solutions

Error 1062 duplicate key means a direct key collision rather than a reservation clash. Error 1205 lock wait timeout may appear if many sessions contend for the same AUTO_INCREMENT counter. Resolve by following similar key management practices.

Common Causes

Explicit Primary Key Update

An UPDATE statement sets the AUTO_INCREMENT column to a value MySQL already earmarked for the same write.

Replication Reordering

Different row execution order on replica and primary leads to conflicting keys during row-based replication.

Bulk Data Migration

Scripts that copy rows with fixed primary keys ignore existing counters and create clashes.

Concurrent Inserts

High-throughput workloads reserve keys in multiple sessions, increasing the chance of overlaps.

Related Errors

Error 1062 duplicate entry

Occurs when a unique index violation happens directly, not due to reserved keys.

Error 1205 lock wait timeout

Shows that sessions are blocked while waiting for the AUTO_INCREMENT lock, often seen in high concurrency.

Error 1467 failed to open file

Indicates storage layer issues that can also interrupt auto increment generation.

FAQs

Does this error occur on INSERT statements?

Yes, but only when INSERT uses ON DUPLICATE KEY UPDATE or a similar clause that updates the AUTO_INCREMENT column within the same statement.

Can I disable the conflict check?

No. MySQL enforces this guard to protect data integrity. The only remedy is to change your query or reseed the counter.

Will changing the column to BIGINT help?

Moving to BIGINT prevents exhaustion but does not remove conflicts with reserved keys. Proper key management is still required.

How does Galaxy help?

Galaxy surfaces current AUTO_INCREMENT values in its schema panel and flags manual key edits in reviews, preventing conflicts before they reach production.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo