开发者

mysql - can I set VARCHAR default value as NULL?

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

  ALTER TABLE  `etexts` CHANGE  `etext`  `etext` VARCHAR( 100 ) CHARACTER SET latin1 COLLATE la开发者_Python百科tin1_swedish_ci NOT NULL DEFAULT NULL

I got the response:

  #1067 - Invalid default value for 'etext' 

Why?


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;


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜