先使字段col为空的都填上默认值 ‘0’:
update yourtable set col=0 where col is null
然后再col字段上加not null约束:
alter table yourtable modify column_name datatype not null;
update yourtable set col=0 where col is null
然后再col字段上加not null约束:
alter table yourtable modify column_name datatype not null;