MySQL - How to modify a column to become Nullable?
Using SQL Query:
Columns are nullable by default, so for an existing column with NOT NULL
defined, you just have to modify it, put in the same data type but remove the NOT NULL
part:
ALTER TABLE table_name MODIFY col_name data_type;
Or use CHANGE
:
ALTER TABLE table_name CHANGE col_name col_name data_type DEFAULT NULL;
DEFAULT NULL
is optional.
Using TablePlus GUI Tool:
- From the table view, switch to the database structure at the bottom
- Select the column you want to modify
- Select
column_defaul
and chooseNULL
- Remember to hit Cmd + S to commit changes to the server
Need a good GUI Tool for MySQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.