MySQL Error 1069 occurs when a table definition exceeds the maximum number of allowed indexes (typically 64). This error commonly arises in ORMs and migrations that automatically create indexes for foreign keys. Resolve it by reviewing and consolidating redundant indexes or using composite indexes instead of multiple single-column indexes.
MySQL enforces a maximum limit on the number of indexes (keys) per table to maintain optimal performance and prevent wasteful index proliferation. By default, this limit is 64 indexes for both InnoDB and MyISAM storage engines. When you attempt to create a table or add an index that would exceed this limit, MySQL immediately rejects the operation with Error 1069. This error is a protective measure—having too many indexes on a single table can slow down write operations, increase memory usage, and degrade query optimizer effectiveness. Each index requires maintenance during INSERT, UPDATE, and DELETE operations, so excessive indexing becomes a liability rather than an asset.
Run this query to see how many indexes your table currently has:
SHOW INDEX FROM your_table_name;This output shows:
- Each index (including PRIMARY, UNIQUE, FOREIGN KEY indexes)
- The column(s) each index covers
- The index type and size
Count the number of distinct index names. If you see 64 or more unique index names, you have hit the limit.
Review the index list and look for:
- Duplicate indexes covering the same columns
- Overlapping indexes where one is a prefix of another (e.g., INDEX(a) and INDEX(a, b))
- Indexes on foreign key columns that already have indexes through the foreign key constraint itself
For example, if you have both:
INDEX idx_user_id ON orders(user_id);
FOREIGN KEY (user_id) REFERENCES users(id);The foreign key already creates an index, so the explicit index is redundant.
Drop indexes that are duplicated or unnecessary:
DROP INDEX index_name ON your_table_name;After dropping each index, verify it was removed:
SHOW INDEX FROM your_table_name;Typically, you can safely remove:
- Duplicate indexes
- Single-column indexes that are subsets of composite indexes
- Indexes created by the ORM that you don't actually query on
Instead of creating separate indexes for each column you query, combine them:
Before (4 separate indexes):
CREATE INDEX idx_user_id ON orders(user_id);
CREATE INDEX idx_status ON orders(status);
CREATE INDEX idx_created_at ON orders(created_at);
CREATE INDEX idx_amount ON orders(amount);After (1-2 composite indexes):
CREATE INDEX idx_user_status_date ON orders(user_id, status, created_at);
CREATE INDEX idx_amount ON orders(amount);Composite indexes are more efficient—they reduce total index count while still supporting your queries (as long as query columns match the index column order).
If you are using Django, Laravel, Prisma, or another ORM:
Prisma example:
Instead of creating an index for every foreign key:
model Order {
id String @id
userId String @db.VarChar(255)
user User @relation(fields: [userId], references: [id])
// Don't add: @@index([userId]) — the foreign key index is enough
}Django example:
In your model, use db_index=False on foreign keys that don't need explicit indexing:
class Order(models.Model):
user = ForeignKey(User, on_delete=models.CASCADE, db_index=False)Edit your migration files to remove redundant index declarations before applying them.
Once you have removed or consolidated indexes, recount them:
SHOW INDEX FROM your_table_name;The unique index count should now be below 64. If you are still above 64 and cannot remove more indexes without breaking application queries, consider the advanced options below.
In rare cases where you genuinely need more than 64 indexes and cannot further consolidate them, InnoDB in MySQL 5.7.7+ supports up to 3,500 secondary indexes per table, which is enforced at table creation time. However, having more than 64 indexes is almost always a sign of poor schema design. Before increasing limits, consult your DBA. Recompiling MySQL to increase MAX_INDEXES above 64 is theoretically possible (max 255) but extremely uncommon and not recommended for production systems. Consider instead denormalizing your schema, partitioning the table, or refactoring your application logic to reduce the number of indexes required.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions