Mysql - can I set the default value of VARCHAR to NULL?

In mysql, I tried to modify an existing table as follows:

  ALTER TABLE  `etexts` CHANGE  `etext`  `etext` VARCHAR( 100 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT NULL

Got a response:

  #1067 - Invalid default value for 'etext' 

Why?

+3
source share
2 answers

This is inconsistent ... NOT NULLbut make it the default NULL...
Delete DEFAULT NULLand change NOT NULLto NULL:

ALTER TABLE  `etexts` CHANGE  `etext`  `etext` VARCHAR( 100 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL;
+9
source

The NOT NULL column has a default value of NULL.

If you want it to be NULLable,

... COLLATE latin1_swedish_ci NULL 

NULLABLE columns will default to NULL automatically if the column

+1
source

Source: https://habr.com/ru/post/1762290/


All Articles