MySQL alter table modify column failing at rows with null values

If your column has NULL values, you can't alter it to be "NON NULL". Change the NULL values first to something else, then try it.


I have just encountered this error, and it seems the solution was to use the IGNORE statement:

ALTER IGNORE TABLE `table` CHANGE COLUMN `col` `col` int(11) NOT NULL;

Note that you may still have data truncation issues, so be sure this is the desired result. Using the IGNORE statement it will suppress the data truncated errors for NULL values in columns (and possibly other errors!!!)


First remove any null values

UPDATE merchant_ftp_account SET fielddelimiter='t' WHERE fielddelimiter IS NULL;

Then

ALTER TABLE merchant_ftp_account MODIFY COLUMN `fielddelimiter` char(1) NOT NULL DEFAULT 't';

Tags:

Mysql