3

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?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
tzmatt7447
  • 2,329
  • 9
  • 24
  • 31

2 Answers2

11

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;
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
1

You can't have a NOT NULL column defaulting to NULL.

If you want it to be NULLable then

... COLLATE latin1_swedish_ci NULL 

NULLABLE columns will default to NULL automagically if no value is provided for the column

StuartLC
  • 104,537
  • 17
  • 209
  • 285