MySQL Alter table causes Error: Invalid use of NULL value

前端 未结 3 1695
甜味超标
甜味超标 2020-12-23 16:07

My existing table:

+-----------------+---------------+------+-----+---------+-------------------+
| Field           | Type          | Null | Key | Default |          


        
3条回答
  •  臣服心动
    2020-12-23 16:31

    It looks like there are few rows with NULL value.Update all null values to a default date in that column and then try to do a alter.

    Try this

    --update null value rows
    UPDATE enterprise
    SET creation_date = CURRENT_TIMESTAMP
    WHERE creation_date IS NULL;
    
    
    ALTER TABLE enterprise 
    MODIFY creation_date TIMESTAMP NOT NULL 
    DEFAULT CURRENT_TIMESTAMP;
    

提交回复
热议问题