Mysql 错误:#1075
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13963002/
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
Mysql Error: #1075
提问by user1888406
SQL query:
SQL查询:
ALTER TABLE `blog` CHANGE `id` `id` BIGINT NOT NULL AUTO_INCREMENT
MySQL said:
MySQL 说:
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
I am trying to create a blog, and I got the code done. Now, I need to make the id
auto increase, but I get this error. Why am I getting this?
我正在尝试创建一个博客,并且我完成了代码。现在,我需要进行id
自动增加,但出现此错误。为什么我得到这个?
回答by spencer7593
MySQL is returning that error (most likely) because there is no unique index defined on the id
column. (MySQL requires that there be a unique index. The other possibility, which you would have already figured out, is that there can be only one column defined as AUTO_INCREMENT within the table.)
MySQL 返回该错误(最有可能),因为该id
列上没有定义唯一索引。(MySQL 要求有一个唯一索引。另一种可能,您已经想到了,是表中只能有一个定义为 AUTO_INCREMENT 的列。)
To get that column to be an AUTO_INCREMENT, you can add either a UNIQUE constraint or a PRIMARY KEY constraint on the id
column. For example:
要使该列成为 AUTO_INCREMENT,您可以在该id
列上添加 UNIQUE 约束或 PRIMARY KEY 约束。例如:
ALTER TABLE `blog` ADD CONSTRAINT `blog_ux` UNIQUE (`id`) ;
(Note that this statement will return an error if any duplicate values exist for the id column.)
(请注意,如果 id 列存在任何重复值,则此语句将返回错误。)
Alternatively, you can make the id column the PRIMARY KEY of the table (if the table doesn't already have a PRIMARY KEY constraint defined).
或者,您可以将 id 列设为表的 PRIMARY KEY(如果该表尚未定义 PRIMARY KEY 约束)。
ALTER TABLE `blog` ADD PRIMARY KEY (`id`) ;
(Note that this statement will return an error if any duplicate value exist for the id column, OR if there are any NULL values stored in that column, of if there is already a PRIMARY KEY constraint defined on the table.)
(请注意,如果 id 列存在任何重复值,或者如果该列中存储了任何 NULL 值,或者如果表上已经定义了 PRIMARY KEY 约束,则此语句将返回错误。)
回答by codingbiz
MySQL requires you to make auto increment column the primary key of a table. Add the primary key
constraint at the end
MySQL 要求您将自增列作为表的主键。最后添加primary key
约束
ALTER TABLE `blog` MODIFY COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT primary key
回答by Anirudh Sood
To resolve #1075 error
message you need to mark atleast one column as primary_key
or unique_key
. that you have forgot to do.
要解析#1075 error
消息,您需要将至少一列标记为primary_key
或unique_key
。你忘了做。
By defining Primary _key
on IDcolumn my error is resolved guys.
通过Primary _key
在ID列上定义我的错误解决了伙计们。
thanks,
谢谢,
Anirudh Sood.
阿尼鲁德·苏德。