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
Let's say that, for example, you have a table structure like below, very simple:
When you want to save this tanle you will see the below pop-up:
Many people will want to add the "Size" of the ID column:
After that is added, you click "Go" and when you want to "Save" the table, you will get this error message:
If you click on "Preview" button, you will see the SQL code:
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:
This will generate the table with no problems.
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!
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.