php 不正确的前缀键 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34095444/
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
Incorrect prefix key MySQL
提问by Erik Neller
I have a problem creating a table with phpmyadmin, which gives me the following error:
我在使用 phpmyadmin 创建表时遇到问题,这给了我以下错误:
#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 - 不正确的前缀键;使用的键部分不是字符串,使用的长度比键部分长,或者存储引擎不支持唯一前缀键
This is the query that I do:
这是我做的查询:
CREATE TABLE `b2b`.`users` ( `id` BIGINT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(30) NOT NULL ,
`surnames` VARCHAR(80) NOT NULL ,
`birthdate` DATE NOT NULL ,
`drivingdoc` VARCHAR(20) NOT NULL ,
`acdate` DATE NOT NULL ,
`countrydoc` VARCHAR(20) NOT NULL ,
`province` VARCHAR(20) NOT NULL ,
`locality` VARCHAR(35) NOT NULL ,
`address` VARCHAR(150) NOT NULL ,
`number` VARCHAR(20) NOT NULL ,
`flat` VARCHAR(20) NOT NULL ,
`door` VARCHAR(20) NOT NULL ,
`description` VARCHAR(2000) NOT NULL ,
PRIMARY KEY (`id`(7))) ENGINE = InnoDB;
Using MariaDB in ubuntu minimal.
在 ubuntu 中使用 MariaDB 最小。
回答by Sammitch
The problem is:
问题是:
PRIMARY KEY (`id`(7))
You cannot use partof a number as a key, you have to use the whole thing. Also, specifying lengths for numeric types is useless at best, and damaging at worst.
您不能使用数字的一部分作为键,您必须使用整个事物。此外,为数字类型指定长度充其量是无用的,最坏的情况是有害的。
Change to:
改成:
PRIMARY KEY (`id`)
回答by Kenney
That Primary Key syntax is nothing I've ever seen before. Try this:
我以前从未见过这种主键语法。尝试这个:
CREATE TABLE `b2b`.`users` (
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
....
) ENGINE = InnoDB;
Or if you want
或者如果你想要
CREATE TABLE `b2b`.`users` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
....
PRIMARY KEY (id)
) ENGINE = InnoDB;
回答by Sergey Belyakov
You have several errors in your sql, so try to find the difference with this sql
你的sql有几个错误,所以试着找出这个sql的不同之处
CREATE TABLE `b2b`.`users` ( `id` INT(7) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(30) NOT NULL ,
`surnames` VARCHAR(80) NOT NULL ,
`birthdate` DATE NOT NULL ,
`drivingdoc` VARCHAR(20) NOT NULL ,
`acdate` DATE NOT NULL ,
`countrydoc` VARCHAR(20) NOT NULL ,
`province` VARCHAR(20) NOT NULL ,
`locality` VARCHAR(35) NOT NULL ,
`address` VARCHAR(150) NOT NULL ,
`number` VARCHAR(20) NOT NULL ,
`flat` VARCHAR(20) NOT NULL ,
`door` VARCHAR(20) NOT NULL ,
`description` VARCHAR(255) NOT NULL ,
PRIMARY KEY (`id`)) ENGINE = InnoDB;