解决mysql建表报错ERROR 1075

解决mysql建表报错ERROR 1075 (42000): Incorrect table definition...


DATE: 2017-11-02 12:38:30

已有一张表,在创建第二张表如下:

CREATE TABLE IF NOT EXISTS `postclass`(
   `id` INT UNSIGNED AUTO_INCREMENT,   
   `class` TEXT,   
   `father_id` INT UNSIGNED,
   `id_level` INT UNSIGNED,
   PRIMARY KEY ( `id` )
)ENGINE=yixzm DEFAULT CHARSET=utf8;

报错:

ERROR 1075 (42000): Incorrect table definition; there can be only one auto colum n and it must be defined as a key

原因:
第一张表里有key是自增的id值,而一个数据库db中不能有两表同时有自增id。

删除自增类型

AUTO_INCREMENT

更改sql命令则解决问题。命令如下:

CREATE TABLE IF NOT EXISTS `postclass`(
   `id` INT UNSIGNED,   
   `class` TEXT,   
   `father_id` INT UNSIGNED,
   `id_level` INT UNSIGNED,
   PRIMARY KEY ( `id` )
)ENGINE=yixzm DEFAULT CHARSET=utf8;
版权声明

弈心博客


本文首发site_name,转载请附上博文链接!