43
CREATE TABLE `movies`.`movie`
( `movie_id` INT(3) NULL AUTO_INCREMENT, `movie_name` VARCHAR(25) NULL,
  `movie_embedded_id` VARCHAR(50) NULL, `rating_no` INT(3) NULL,
  `movie_description` VARCHAR(50) NULL, PRIMARY KEY (`movie_id`(3))) ENGINE = InnoDB;

I keep getting this error:

#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.

but I've got no idea what it means, anyone have a clue?

2
  • 2
    Its probably this PRIMARY KEY (`movie_id`(3)) change it to PRIMARY KEY (`movie_id`)
    – Dan
    May 22, 2015 at 21:30
  • 1
    For me, i will just save it without having primary key. Once you save it, just edit the table at structure Dec 7, 2016 at 7:27

4 Answers 4

123

With the part

PRIMARY KEY (`movie_id`(3))

you are telling mysql to create a sub part key* on the first 3 Bytes of movie id. This only works for string types.

You need to use

PRIMARY KEY (`movie_id`)

without providing a length.

*Is this sure the query resulting in the error? Never saw that on a primary key, its used for indexes.

1
  • thank you very much, i didn't realise this was what i was requesting.
    – tinOfBeans
    May 22, 2015 at 21:47
25

after selecting PRIMARY KEY when you create table, don't input any value in pop dialog

1
  • You gave the exact solution what we need. Thanks. May 8, 2019 at 10:35
5

You can also get this error when creating an index if you specify a prefix length that is longer than the length of the actual column. If you tried to create an index containing someColumn(20) but in the table someColumn is VARCHAR(15), then this error will occur.

0

For the primary key do not enter any length of type.

Example:
int()

Not the answer you're looking for? Browse other questions tagged or ask your own question.