我一直得到这个mysql错误代码#1089

时间:2021-03-20 21:46:31
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.

#1089 - 前缀键不正确;使用的关键部分不是字符串,使用的长度比关键部分长,或者存储引擎不支持唯一的前缀键。

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

但我不知道这意味着什么,任何人都有线索?

3 个解决方案

#1


70  

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.

你告诉mysql在电影ID的前3个字节上创建一个子部分键*。这仅适用于字符串类型。

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.

*这确定查询导致错误吗?从未在主键上看到它,它用于索引。

#2


2  

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

在创建表时选择PRIMARY KEY后,不要在弹出对话框中输入任何值

#3


1  

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.

如果指定的前缀长度超过实际列的长度,则在创建索引时也会出现此错误。如果您尝试创建包含someColumn(20)的索引但在表someColumn是VARCHAR(15)中,则会发生此错误。

#1


70  

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.

你告诉mysql在电影ID的前3个字节上创建一个子部分键*。这仅适用于字符串类型。

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.

*这确定查询导致错误吗?从未在主键上看到它,它用于索引。

#2


2  

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

在创建表时选择PRIMARY KEY后,不要在弹出对话框中输入任何值

#3


1  

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.

如果指定的前缀长度超过实际列的长度,则在创建索引时也会出现此错误。如果您尝试创建包含someColumn(20)的索引但在表someColumn是VARCHAR(15)中,则会发生此错误。