Search code examples
mysqlsqlnulldefaultdefault-value

desc table in mysql say Null is No but default is NULL?


I am using mysql for a project. When I did 'desc table_name', I see that the tabular output shows the Null of the field is set to No, but then 'Default' is set to NULL. How can a field not have a Null but then default is Null itself?

mysql> desc users;                                                                                 
+-----------------+------------------+------+-----+----------------------------+----------------+  
| Field           | Type             | Null | Key | Default                    | Extra          |  
+-----------------+------------------+------+-----+----------------------------+----------------+  
| id              | int(10) unsigned | NO   | PRI | NULL                       | auto_increment |  
| created_at      | timestamp        | YES  |     | NULL                       |                |  
| updated_at      | timestamp        | YES  |     | NULL                       |                |  
| email           | varchar(255)     | NO   |     | NULL                       |                |  
| password        | varchar(255)     | NO   |     | NULL                       |                |  
| remember_token  | varchar(100)     | YES  |     | NULL                       |                |  
| profile_pic     | varchar(255)     | YES  |     | img/profile/profilepic.jpg |                |  
| activation_code | varchar(255)     | YES  | UNI | NULL                       |                |  
| status_id       | int(10) unsigned | NO   | MUL | 1                          |                |  
| profile_id      | int(10) unsigned | YES  | MUL | NULL                       |                |  
+-----------------+------------------+------+-----+----------------------------+----------------+  
10 rows in set (0.00 sec)                                                                          

Solution

  • This is a perfectly legal combination. It means that when you try to insert a new row and do not explicitly specify this column's value, it would default to null and thus error out. This combination is often used as a way to force you to explicitly assign a value to the column instead of just relying on defaults.