Running mariadb 10.3
I have a bunch of columns that were created by default as NULL defaults. I was asked by a third party integrator to remove the NULL defaults, but so far have been unsuccessful.
I first do:
mysql> Describe Tablename;
I see my columns with Null defaults. e.g:
+--------------------------+---------------------+------+-----+---------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+---------------------+------+-----+---------+-------------------+
| Tech ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| State | tinyint(1) unsigned | NO | | 1 | |
| Ref ProdID | int(10) unsigned | NO | MUL | NULL | |
| Prenom | varchar(50) | YES | | NULL | |
Then I do:
mysql>ALTER TABLE Tablename ALTER COLUMN Prenom DROP DEFAULT;
Query OK, 0 rows affected (0.002 sec)
Records: 0 Duplicates: 0 Warnings: 0
Describe again shows that the Null default has not been removed from column Prenom
.
+--------------------------+---------------------+------+-----+---------+-------------------+
| Tech ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| State | tinyint(1) unsigned | NO | | 1 | |
| Ref ProdID | int(10) unsigned | NO | MUL | NULL | |
| Prenom | varchar(50) | YES | | NULL | |
Is it even possible to do this?
Best Answer
Does remove the default as showed in
SHOW CREATE TABLE
and attempting to insert without a value results in an error.It appears
DESCRIBE TABLE
is using NULL as both a literal, and without a value in its output. Always rely onSHOW CREATE TABLE
db<>fiddle here