首页 > 代码库 > pt-online-schema-change和默认值关系
pt-online-schema-change和默认值关系
在使用pt-online-schema-change会遇到如下的错误导致表修改失败:
Copying rows caused a MySQL error 1364,Message: Field ‘XXX‘ doesn‘t have a default value
例子1:
#修改的SQL:ALTER TABLE `live_comment` ADD `sourcefrom` VARCHAR(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ‘来源标志‘ AFTER `ip`, ADD `type` INT UNSIGNED NOT NULL DEFAULT ‘0‘ COMMENT ‘评论类型‘ AFTER `sourcefrom`, ADD INDEX (`type`)
错误信息为:
`sportslive`.`live_comment` was not altered.Error copying rows from `sportslive`.`live_comment` to `sportslive`.`_live_comment_new`: Copying rows caused a MySQL error 1364: Level: Warning Code: 1364 Message: Field ‘sourcefrom‘ doesn‘t have a default value
对应的表结构为:
CREATE TABLE `sportslive`.`_live_comment_new` ( `id` int(11) NOT NULL AUTO_INCREMENT, `live_id` int(11) NOT NULL DEFAULT ‘0‘, `content` varchar(200) NOT NULL DEFAULT ‘‘, `reply_uid` bigint(20) NOT NULL DEFAULT ‘0‘, `reply_username` varchar(30) NOT NULL DEFAULT ‘‘, `reply_content` varchar(200) NOT NULL DEFAULT ‘‘, `reply_profile_pic` varchar(100) NOT NULL DEFAULT ‘‘, `parent_id` int(11) NOT NULL, `uid` bigint(20) NOT NULL DEFAULT ‘0‘, `username` varchar(30) NOT NULL DEFAULT ‘‘, `profile_pic` varchar(100) NOT NULL DEFAULT ‘‘, `addtime` datetime NOT NULL, `ip` varchar(15) NOT NULL DEFAULT ‘‘, `prior` tinyint(4) NOT NULL DEFAULT ‘0‘ COMMENT ‘xxxx‘, PRIMARY KEY (`id`), KEY `live_id` (`live_id`)) ENGINE=InnoDB AUTO_INCREMENT=296173 DEFAULT CHARSET=utf8
例子2:
修改的SQL:
ALTER TABLE `mb_post_spider_1209` CHANGE `category` `category` VARCHAR(8) NOT NULL COMMENT ‘‘, CHANGE `reposts_count` `reposts_count` INT(11) UNSIGNED NOT NULL DEFAULT ‘0‘ COMMENT ‘‘, CHANGE `heat` `heat` DECIMAL(8,5) UNSIGNED NOT NULL DEFAULT ‘0.00000‘ COMMENT ‘‘, CHANGE `spider_date` `spider_date` INT(8) UNSIGNED NOT NULL DEFAULT ‘0‘ COMMENT ‘抓取时间‘, CHANGE `main_cat` `main_cat` TINYINT(1) NOT NULL COMMENT ‘‘, CHANGE `sub_cat` `sub_cat` TINYINT(1) NOT NULL COMMENT ‘‘, CHANGE `state` `state` TINYINT(1) UNSIGNED NOT NULL DEFAULT ‘0‘ COMMENT ‘‘, CHANGE `bid` `bid` BIGINT(20) UNSIGNED NOT NULL DEFAULT ‘0‘ COMMENT ‘‘, CHANGE `bname` `bname` VARCHAR(32) NOT NULL COMMENT ‘‘
Warning信息如下:
Error copying rows from `mb_content`.`mb_post_spider_1209` to `mb_content`.`_mb_post_spider_1209_new`: Copying rows caused a MySQL error 1048: Level: Warning Code: 1048 Message: Column ‘bname‘ cannot be null
http://www.mysqlperformanceblog.com/2012/06/21/pt-online-schema-change-and-default-values/
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。