Mysql 修改字段默认值问题

临下班前,测试测出所有的返回报文中有一个版本号的值没有上送,最后定位是由于数据库配置表里版本号是空。

这应该属于前辈们留下的bug了....

首先试了下

ALTER TABLE newftp alter column command_version varchar(10) not NULL default 'v1.0'

报错了:[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(10) not NULL  default 'v1.0'' at line 1;

之后又从网上搜了:

ALTER TABLE newftp add DEFAULT ('v1.0') for command_version WITH VALUES,然而也是执行失败:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT ('v1.0') for command_version WITH VALUES' at line 1

后来用navcat工具修改字段默认值,然后点SQL预览,

拿出一条新SQL:

ALTER TABLE `newftp` MODIFY COLUMN `command_version` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT "v1.0" COMMENT '版本号'

后来我把之前的alter换成了modify

ALTER TABLE newftp MODIFY column command_version varchar(10) not NULL default 'v1.0'

执行成功了...

原文地址:https://www.cnblogs.com/twelve-eleven/p/6961312.html