我不断收到此 mysql 错误代码 #1089

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30406066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:01:53  来源:igfitidea点击:

I keep getting this mysql error code #1089

mysql

提问by tinOfBeans

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?

但我不知道这是什么意思,有人知道吗?

回答by dognose

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 个字节上创建一个子部分 key*。这仅适用于字符串类型。

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.

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

回答by Albert Nguyen

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

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

回答by Wandering Zombie

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 someColumnis VARCHAR(15), then this error will occur.

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