简体   繁体   English

将MySQL栏变更为AUTO_INCREMENT时发生错误

[英]Error changing MySQL column to AUTO_INCREMENT

Here is my current table design: 这是我当前的表格设计:

在此处输入图片说明

I have several columns and no KEYs set, so when I try the following command: 我有几列,并且没有设置键,因此当我尝试以下命令时:

ALTER TABLE users MODIFY COLUMN id INT auto_increment;

it gives me an error. 这给了我一个错误。 I want the id column in the table to auto-increment and I want it to start with 1. 我希望表格中的id列自动递增,并希望它以1开头。

I think you are missing the primary key definition. 我认为您缺少主键定义。 Try this: 尝试这个:

ALTER TABLE users MODIFY id INT AUTO_INCREMENT PRIMARY KEY

Also, I recommend you check this out. 另外,我建议你检查这个了。

您必须使用AUTO_INCREMENT指定PRIMARY_KEY

ALTER TABLE users MODIFY id INT PRIMARY_KEY AUTO_INCREMENT;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM