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.

Answer from Isaac Bennetch on Stack Overflow
🌐
W3Schools
w3schools.com › mysql › mysql_notnull.asp
MySQL NOT NULL Constraint
MySQL Examples MySQL Editor MySQL Quiz MySQL Exercises MySQL Syllabus MySQL Study Plan ... The NOT NULL constraint enforces a column to NOT accept NULL values.
🌐
PopSQL
popsql.com › learn-sql › mysql › how-to-add-a-not-null-constraint-in-mysql
How to Add a Not Null Constraint in MySQL
To enforce NOT NULL for a column in MySQL, you use the ALTER TABLE .... MODIFY command and restate the column definition, adding the NOT NULL attribute. --Example: Products have a default stock of 0 ALTER TABLE products MODIFY stocks INT NOT ...
🌐
YouTube
youtube.com › watch
MySQL Database Tutorial - 30 - NOT NULL & AUTO INCREMENT - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2026 Google LLC
Published   January 25, 2012
🌐
TechOnTheNet
techonthenet.com › mysql › is_not_null.php
MySQL: IS NOT NULL
Here is an example of how to use the MySQL IS NOT NULL condition in an UPDATE statement: UPDATE contacts SET status = 'completed' WHERE last_name IS NOT NULL;
🌐
CopyProgramming
copyprogramming.com › howto › setting-a-field-as-not-null-in-phpmyadmin
Php: Making a Field Mandatory in phpMyAdmin
May 17, 2023 - In the Structure tab, search for the "NULL" checkbox while editing the field. If it's unchecked, it corresponds to the NOT NULL statement.
Find elsewhere
🌐
GitHub
github.com › phpmyadmin › phpmyadmin › issues › 12874
Cannot set default value to NOT NULL for a VARCHAR STORED GENERATED column · Issue #12874 · phpmyadmin/phpmyadmin
January 7, 2017 - Steps to reproduce Structure Pick a generated column, Change Uncheck "NULL", and default value to none Expected behaviour Should change default to "None" instead of NULL Actual ...
Author   bs-thomas
🌐
Ubiq BI
ubiq.co › home › how to add not null constraint in mysql
How To Add NOT NULL Constraint in MySQL - Ubiq BI
July 18, 2024 - If you need to set a MySQL column ... MySQL. You can add NOT NULL constraint when you create table table using CREATE TABLE statement, or add NOT NULL constraint in existing table using ALTER TABLE statement....
🌐
Fullstackwebstudio
fullstackwebstudio.com › home › null column with phpmyadmin
Null Column With PHPMYADMIN
April 21, 2012 - To make the column value NULL, 1) Open PHPMYADMIN. 2) Select Structure. 3) Select edit for the desired column. 4) Select ‘Null’ for default. 5) Click the ‘NULL” checkbox.
Top answer
1 of 1
11

What version of mysql is this?

What mode are you running in?

SELECT @@GLOBAL.SQL_MODE, @@SESSION.SQL_MODE;

(This should be run in the context of your application, just in case it is changing it).

MySQL is documented thus: http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html

As of MySQL 5.0.2, if a column definition includes no explicit DEFAULT value, MySQL determines the default value as follows:

If the column can take NULL as a value, the column is defined with an explicit DEFAULT NULL clause. This is the same as before 5.0.2.

If the column cannot take NULL as the value, MySQL defines the column with no explicit DEFAULT clause. For data entry, if an INSERT or REPLACE statement includes no value for
the column, MySQL handles the column according to the SQL mode in effect at the time:

If strict SQL mode is not enabled, MySQL sets the column to the implicit default value for the column data type. 

My own testing fails to duplicate your issue

mysql> CREATE TABLE `my_table` (
    ->   `entry_id` int(11) NOT NULL AUTO_INCREMENT,
    ->   `address` varchar(512) NOT NULL,
    ->   `follow_up_to` int(11) DEFAULT NULL,
    ->   PRIMARY KEY (`entry_id`),
    ->   KEY `follow_up_to` (`follow_up_to`)
    -> ) ENGINE=InnoDB AUTO_INCREMENT=536 DEFAULT CHARSET=latin1;
Query OK, 0 rows affected, 2 warnings (0.16 sec)

mysql> INSERT INTO my_table VALUES (NULL, NULL, NULL);
ERROR 1048 (23000): Column 'address' cannot be null
mysql> INSERT INTO my_table (follow_up_to) VALUES (NULL);
Query OK, 1 row affected, 1 warning (0.10 sec)

mysql> SHOW WARNINGS;
+---------+------+----------------------------------------------+
| Level   | Code | Message                                      |
+---------+------+----------------------------------------------+
| Warning | 1364 | Field 'address' doesn't have a default value |
+---------+------+----------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM my_table;
+----------+---------+--------------+
| entry_id | address | follow_up_to |
+----------+---------+--------------+
|      537 |         |         NULL |
+----------+---------+--------------+
1 row in set (0.00 sec)

The fact the old data had nulls shouldn't matter. The Alter table should have 'truncated' the nulls into empty strings

mysql> SHOW CREATE TABLE my_table\G
*************************** 1. row ***************************
       Table: my_table
Create Table: CREATE TABLE `my_table` (
  `entry_id` int(11) NOT NULL AUTO_INCREMENT,
  `address` varchar(512) NOT NULL,
  `follow_up_to` int(11) DEFAULT NULL,
  PRIMARY KEY (`entry_id`),
  KEY `follow_up_to` (`follow_up_to`)
) ENGINE=InnoDB AUTO_INCREMENT=536 DEFAULT CHARSET=latin1
1 row in set (0.04 sec)

mysql> ALTER TABLE my_table MODIFY address VARCHAR(512) NULL DEFAULT NULL;
Query OK, 1 row affected (0.76 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> INSERT INTO my_table VALUES (NULL, NULL, NULL), (NULL, NULL, NULL);
Query OK, 2 rows affected (0.05 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM my_table;
+----------+---------+--------------+
| entry_id | address | follow_up_to |
+----------+---------+--------------+
|      535 |         |         NULL |
|      536 | NULL    |         NULL |
|      537 | NULL    |         NULL |
+----------+---------+--------------+
3 rows in set (0.04 sec)

mysql> ALTER TABLE my_table MODIFY address VARCHAR(512) NOT NULL;
Query OK, 3 rows affected, 2 warnings (0.83 sec)
Records: 3  Duplicates: 0  Warnings: 2

mysql> SHOW WARNINGS;
+---------+------+----------------------------------------------+
| Level   | Code | Message                                      |
+---------+------+----------------------------------------------+
| Warning | 1265 | Data truncated for column 'address' at row 2 |
| Warning | 1265 | Data truncated for column 'address' at row 3 |
+---------+------+----------------------------------------------+
2 rows in set (0.04 sec)

mysql> SELECT * FROM my_table;
+----------+---------+--------------+
| entry_id | address | follow_up_to |
+----------+---------+--------------+
|      535 |         |         NULL |
|      536 |         |         NULL |
|      537 |         |         NULL |
+----------+---------+--------------+
3 rows in set (0.04 sec)

mysql> INSERT INTO my_table VALUES (NULL, NULL, NULL), (NULL, NULL, NULL);
Query OK, 2 rows affected, 2 warnings (0.08 sec)
Records: 2  Duplicates: 0  Warnings: 2

mysql> SELECT * FROM my_table;
+----------+---------+--------------+
| entry_id | address | follow_up_to |
+----------+---------+--------------+
|      535 |         |         NULL |
|      536 |         |         NULL |
|      537 |         |         NULL |
|      538 |         |         NULL |
|      539 |         |         NULL |
+----------+---------+--------------+
5 rows in set (0.05 sec)
Top answer
1 of 2
13

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
2 of 2
7

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

🌐
W3Schools
w3schools.com › mysql › mysql_null_values.asp
MySQL NULL Values - IS NULL and IS NOT NULL
MySQL Examples MySQL Editor MySQL Quiz MySQL Exercises MySQL Syllabus MySQL Study Plan ... If a field in a table is optional, it is possible to insert or update a record without adding any value to this field. This way, the field will be saved with a NULL value.
🌐
Blogger
rani-irsan.blogspot.com › home › mysql query › mysql: menambahkan batasan not null pada tabel
MySQL: Menambahkan batasan NOT NULL pada tabel
December 17, 2019 - Untuk menambahkan NOT NULL pada kolom tabel di MySQL kita menggunakan ALTER TABLE ... MODIFY dan mendefinisikan ulang atribut kolom serta menambahkan atribut NOT NULL. ALTER TABLE namatabel MODIFY namakolom typedata NOT NULL; Kita benar-benar ...
🌐
Home and Learn
homeandlearn.co.uk › php › php12p3.html
setting up fields in a phpmyadmin database tables
If you leave it blank for VARCHAR, you'll get a default value of 1 character (you may even get errors, in later versions of phpMyAdmin). The other Field settings we'll take a look at are these: ... Null This is an important field in database terminology. It essentially means, "Should the field contain anything?" If you set a field to NOT NULL, then you can't leave it blank when you come to adding records to your database.