views:

55

answers:

2

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?

+3  A: 

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
Thanks - strangely enough, thats what phpmyadmin generated for me!! (what i had pasted above in my question)
tzmatt7447
phpMyAdmin is not always right. You might want to fill in a bug if it's not already reported.
Lekensteyn
A: 

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

nonnb