mysql - can I set VARCHAR default value as NULL?

tzmatt7447 picture tzmatt7447 · Aug 30, 2010 · Viewed 23.6k times · Source

In mysql, i tried changing an existing table like this:

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

I got the response:

  #1067 - Invalid default value for 'etext' 

Why?

Answer

Lekensteyn picture Lekensteyn · Aug 30, 2010

It's contradictive... NOT NULL, but make it default NULL...
Remove DEFAULT NULL and change NOT NULL to NULL:

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