How to fix #1089 - Incorrect prefix key MySQL Error in phpMyAdmin

Introduction

Adding MySQL tables to a database, using phpMyAdmin, it's an easy and pelasant operation.

But some errors can occur, even if you think that you did everything right.

One error which can occur when you want to create a table in your cPanel phpMyAdmin is this one:

#1089 - Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys

#1089 - Incorrect prefix key Issue

Let's say that, for example, you have a table structure like below, very simple:

phpmyadmin table structure

When you want to save this tanle you will see the below pop-up:

table pop up no fill in

Many people will want to add the "Size" of the ID column:

table pop up

After that is added, you click "Go" and when you want to "Save" the table, you will get this error message:

1089 incorrect key prefix

If you click on "Preview" button, you will see the SQL code:

preview sql 1089 error

How to fix 1089 MySQL error when you try to save the table in phpMyAdmin?

Once we get this annoyingm issue, we cannot save the table and continue our work.

What is the solution?

As you have seen above the code looks something like this:

CREATE TABLE `db_name`.`my_table` ( `ID` BIGINT NOT NULL , PRIMARY KEY (`ID`(20))) ENGINE = InnoDB; 

The error is generated by the fact that we have a length added to the Primary Key.

Usually this length is provided to columns having a varchar or char type.

Our code should look like this and there will be no errors:

CREATE TABLE `db_name`.`my_table` ( `ID` BIGINT NOT NULL , PRIMARY KEY (`ID`)) ENGINE = InnoDB; 

Just click on top SQL tab and add the code there:

fix 1089 incorrect prefix key

This will generate the table with no problems.

How to prevent 1089 MySQL error?

If you want to avoid this error to occur, when the pop-up appears just do not input anything.

Just click on "Go". No numbers added! No text or something else!

Conclusion

There are other MySQL errors which you can encounter, but I really hope that reading this article will help you to get rid of "#1089 - Incorrect prefix key" one.

Comments closed

Please contact me, if you have any questions or suggestions.