When editing the field in the Structure tab, look for the "NULL" checkbox. When un-checked, this is the equivalent of the NOT NULL statement.
Videos
You must not have SQL_MODE set to strict on your installation.
Issue
SET SQL_MODE='STRICT_ALL_TABLES'
or add
SQL_MODE='STRICT_ALL_TABLES'
under [mysqld] into your my.cnf
To find my.cnf, look in the MySQL config file C:\xampp\mysql\bin\my.ini.
At the top of that file are some comments:
# You can copy this file to
# C:/xampp/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is C:/xampp/mysql/data) or
# ~/.my.cnf to set user-specific options.
There it tells you where to find your my.cnf file.
Restart your mysql if necessary.
Maybe you have the rights to change the SQL mode via phpMyAdmin. Go the home (starting) page of phpMyAdmin, then click on Variables and enter "SQL mode" in the filter. Then you have access to some explanations via the question mark, and by clicking on this line you can edit the value of SQL mode and save it.
However this would be just for testing purposes, at the setting will revert to its original value once the server is restarted; hence the need to change the configuration file.
There must be a checkbox near input for setting NULL value. ( only on nullable columns )
( alternatievly, I prefer to use SQL language directly )
In phpMyAdmin, there should be a checkbox next to the text field. Checking that should make the field NULL.
If you're using a query, it is:
UPDATE table SET field = NULL WHERE id = 4
It actually doesn't accept NULL values it considers it as empty string. That's because you have your server in non-strict mode. That controls how MySQL handles invalid or missing values in inserts and updates. You can read more about modes here: http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
mysql> insert into cities(state_id) values (20);
Query OK, 1 row affected, 1 warning (0.07 sec)
mysql> show warnings;
+---------+------+-------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------+
| Warning | 1364 | Field 'name' doesn't have a default value |
+---------+------+-------------------------------------------+
mysql> select name is null from cities where id = LAST_INSERT_ID();
+--------------+
| name is null |
+--------------+
| 0 |
+--------------+
1 row in set (0.00 sec)
mysql> SET sql_mode = 'STRICT_ALL_TABLES';
Query OK, 0 rows affected (0.00 sec)
mysql> insert into cities(state_id) values (20);
ERROR 1364 (HY000): Field 'name' doesn't have a default value
To Károly Nagy's point,
You can use
SET SQL_MODE = 'STRICT_ALL_TABLES';
I'm sure you may already know but that is equivilent to:
SET @@SESSION.SQL_MODE = 'STRICT_ALL_TABLES';
Which, must be set for every session. And you can checky this by running this after the above statement.
SELECT @@SESSION.SQL_MODE; -- 'STRICT_ALL_TABLES'
SELECT @@GLOBAL.SQL_MODE; -- 'NO_ENGINE_SUBSTITUTION'
If you have access please set this at the global level:
SET @@GLOBAL.SQL_MODE = 'STRICT_ALL_TABLES';
Which becomes the default for every new session thereafter.
Cheers, Jay ;-]
NOTE: Tested On MySQL Version 5.6.23-log & MySQL Workbench 6.2.5
You want the following:
ALTER TABLE mytable MODIFY mycolumn VARCHAR(255);
Columns are nullable by default. As long as the column is not declared UNIQUE or NOT NULL, there shouldn't be any problems.
Your syntax error is caused by a missing "table" in the query
ALTER TABLE mytable MODIFY mycolumn varchar(255) null;
