【 TiDB 使用环境`】Dev
【 TiDB 版本】v6.1.0
【遇到的问题】
由于无法用Create Table select 命令,使用show create table得到表定义,然后手工创建表后,插入数据时候,遇上ERROR 1364 (HY000): Field ‘xxx’ doesn’t have a default value
【复现路径】随时可以再现
【问题现象及影响】
-
先创建原表
create table testrb(id bigint(20) auto_random primary key,name varchar(2) default null); -
insert 记录
MySQL [raydb]> insert into testrb(name) values(‘tr’);
Query OK, 1 row affected (0.031 sec)
MySQL [raydb]> select * from testrb;
±--------------------±-----+
| id | name |
±--------------------±-----+
| 2017612633061982209 | tr |
±--------------------±-----+
1 row in set (0.003 sec)
-
用show create table获得定义
MySQL [raydb]> show create table testrb;
±-------±------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------+
| Table | Create Table |
±-------±------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------+
| testrb | CREATE TABLEtestrb
(
id
bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
name
varchar(2) DEFAULT NULL,
PRIMARY KEY (id
) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
±-------±------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------+
1 row in set (0.005 sec) -
然后仅把表名更改,复制定义,手工运行
MySQL [raydb]> CREATE TABLEtestrb2
(
->id
bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
->name
varchar(2) DEFAULT NULL,
-> PRIMARY KEY (id
) /*T![clustered_index] CLUSTERED */
-> ) ;
Query OK, 0 rows affected (0.122 sec) -
运行相同insert 仅表名不同
MySQL [raydb]> insert into testrb2(name) values(‘tr’);
ERROR 1364 (HY000): Field ‘id’ doesn’t have a default value -
当然指定ID值是没问题,但失去了auto_random意义
MySQL [raydb]> insert into testrb2(id,name) values(‘1221321’,‘tr’);
Query OK, 1 row affected (0.011 sec)
MySQL [raydb]> select * from testrb2;
±--------±-----+
| id | name |
±--------±-----+
| 1221321 | tr |
±--------±-----+
1 row in set (0.004 sec)
show create table显示的如果和手工创建的不等价,那其意义就没有了。难道AUTO_RANDOM情况
有啥问题
【附件】
- TiUP Cluster Display 信息
- TiUP Cluster Edit Config 信息
- TiDB- Overview 监控