mysql> ALTER TABLE user modify phone int(25) not null;
ERROR 1366 (HY000): Incorrect integer value: '' for column 'phone' at row 1

mysql改变字段类型报错
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
关注
你之前的字段类型是什么?
字段类型不是随便可以改的,尤其是在有数据的情况下
我模拟出来了,你原表中存在有空字符串'',而不是null,因此修改会报错
create table test_20220404_a (b VARCHAR(25) not null); insert into test_20220404_a values (''); ALTER TABLE test_20220404_a modify b int(25) not null;
下面这个方式可以把你的这个字段成功改掉,但是由于你设置了不允许为null,因此只能默认设置个0上去了
ALTER TABLE test_20220404_a modify b VARCHAR(25) ; update test_20220404_a set b=0 where b =''; ALTER TABLE test_20220404_a modify b int(25) not null;
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录