[42000][1075] Incorrect table definition; there can be only one auto column and it must be defined as a key

出现情景:

在当前表格,有添加了主键的auto_increment

但是当删除主键约束的时候提示错误:[42000][1075] Incorrect table definition; there can be only one auto column and it must be defined as a key

本以为是必须为not null,后来测试为索引的问题。

出现原因:

auto_increment必须搭配主键索引或者唯一索引使用。

image-20230206135938124

解决方法:

  1. 删除当前列的auto_increment
  2. 把主键索引替换为唯一索引