Change Table Column to Not Null

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 表字段改成not null

| username: weibiao

To improve efficiency, please provide the following information. A clear problem description can lead to a quicker resolution:
【TiDB Usage Environment】

【Overview】 Scenario + Problem Overview

【Background】 Actions taken

【Phenomenon】 Business and database phenomena

【Problem】 Current issue encountered

【Business Impact】

【TiDB Version】 v5.2.4

【Application Software and Version】
This is the previous table field: file_save_path varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘File save path’,
The screenshot shows an attempt to change it to not null. Why is this error occurring?

| username: weibiao | Original post link

Execute this: update t1 set file_save_path = "" where file_save_path is null; and it should work.

| username: xfworld | Original post link

The file_save_path should have data. When there is a DDL change, it will first check if there is any data corruption.

It won’t pass the check, right?

| username: weibiao | Original post link

Yes, that’s right. Updating null to “” will work. However, rebuilding the data is very slow.

| username: xfworld | Original post link

Create a new table and move the data over… :joy: