Altering MySQL Column to Allow NULL Values
A user attempts to modify a MySQL column to permit NULL values using the syntax:
ALTER mytable MODIFY mycolumn varchar(255) null;
However, the server reports syntax errors.
Problem Investigation and Resolution
The correct syntax for altering a table to allow NULL values for a column is:
ALTER TABLE mytable MODIFY mycolumn VARCHAR(255);
By default, columns in MySQL are nullable unless explicitly declared as UNIQUE or NOT NULL. Therefore, simply changing the column type to VARCHAR(255) without specifying any constraints is sufficient to make it nullable.
The above is the detailed content of How to Correctly Allow NULL Values in a MySQL Column?. For more information, please follow other related articles on the PHP Chinese website!