问题描述:mysql在给表新增主键时报错ERROR 1063,如下所示:
数据库:mysql 5.7.21
1、模拟异常
1.1、建测试表
mysql> create table fruits
-> (
-> s_id int not null,
-> f_name char(255) not null,
-> f_price decimal(8,2) not null
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> desc fruits;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| s_id | int(11) | NO | | NULL | |
| f_name | char(255) | NO | | NULL | |
| f_price | decimal(8,2) | NO | | NULL | |
+---------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
1.2、新增字段与主键
mysql> alter table fruits add f_id char(10) not null comment '主键ID';
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table fruits change f_id f_id char(10) not null comment '主键ID' auto_increment primary key;
ERROR 1063 (42000): Incorrect column specifier for column 'f_id'
说明:如上所示,添加主键时报错ERROR 1063.
2、异常原因
auto_increment columns must be integer type (TINYINT, SMALLINT, INTEGER, or BIGINT)
3、解决方案
--调整f_id为bigint类型.
mysql> alter table fruits drop f_id;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc fruits;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| s_id | int(11) | NO | | NULL | |
| f_name | char(255) | NO | | NULL | |
| f_price | decimal(8,2) | NO | | NULL | |
+---------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> alter table fruits add f_id bigint(20) not null comment '主键ID';
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table fruits change f_id f_id bigint(20) not null comment '主键ID' auto_increment primary key;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
说明:如上所示,成功添加主键.mysql在给表新增主键时报错ERROR 1063
原创Liujun_Deng 博主文章分类:Mysql ©著作权
©著作权归作者所有:来自51CTO博客作者Liujun_Deng的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
登录mysql时报错ERROR 1524
登录mysql时报错ERROR 1524
MySQL ERROR 1524 -
mysql在删索引时报错ERROR 1075
mysql在删索引时报错ERROR 1075
mysql ERROR 1075 -
mysql在新建用户时报错ERROR 1819
mysql在新建用户时报错ERROR 1819
MySQL ERROR 1819 -
连接mysql数据库时报错ERROR 1130
连接mysql数据库时报错ERROR 1130
MySQL ERROR 1130 连接异常 -
mysql 批量增加表主键 mysql批量新增返回主键
一、 insert元素 其属性如下:parameterTypekeyColumnkeyPropertyuseGeneratedKeysstatementTypeflushCachetimeout ,默认为unset(依赖jdbc驱动器的设置),设置执行该操作的最大时限,超时将抛异常二、一般的INSERT操作——返回值为插入的记录数目
mysql 批量增加表主键 MyBatis insert keyProperty selectKey -
JavaScript编程工具有哪些?老前端的实用工具清单与经验分享
本文介绍常用 JavaScript 编程工具,包括 VS Code、WebStorm、Vite、Webpack、Chrome DevTools
#前端 #javascript #开发语言 #ios #小程序
















