2015-08-15 142 views
2

的默認值表錯誤,當我在創建一個表phpMyAdmin的,我收到此錯誤:MySQL的:創建枚舉

#1067 - Invalid default value for 'htmlstate'

查詢創建表:

CREATE TABLE `cms_article` (
    `contentid` int(10) unsigned NOT NULL AUTO_INCREMENT, 
    `pagetext` mediumtext /*!40101 COLLATE latin1_bin */ NOT NULL, 
    `threadid` int(10) unsigned DEFAULT NULL, 
    `blogid` int(10) unsigned DEFAULT NULL, 
    `posttitle` varchar(255) /*!40101 COLLATE latin1_bin */ DEFAULT NULL, 
    `postauthor` varchar(100) /*!40101 COLLATE latin1_bin */ DEFAULT NULL, 
    `poststarter` int(10) unsigned DEFAULT NULL, 
    `blogpostid` int(10) unsigned DEFAULT NULL, 
    `postid` int(10) unsigned DEFAULT NULL, 
    `post_posted` int(10) unsigned DEFAULT NULL, 
    `post_started` int(10) unsigned DEFAULT NULL, 
    `previewtext` varchar(2048) /*!40101 COLLATE latin1_bin */ DEFAULT NULL, 
    `previewimage` varchar(256) /*!40101 COLLATE latin1_bin */ DEFAULT NULL, 
    `imagewidth` int(10) unsigned DEFAULT NULL, 
    `imageheight` int(10) unsigned DEFAULT NULL, 
    `previewvideo` mediumtext /*!40101 COLLATE latin1_bin */, 
    `htmlstate` enum('off','on','on_nl2br') /*!40101 COLLATE latin1_bin */ NOT NULL DEFAULT 'off', 
    PRIMARY KEY (`contentid`) 
) ENGINE=InnoDB AUTO_INCREMENT=503 /*!40101 DEFAULT CHARSET=latin1 */ /*!40101 COLLATE=latin1_bin */; 
+0

mysql服務器版本? – Jigar

+0

這適用於SQL小提琴版本5.5。 。 。 http://www.sqlfiddle.com/#!2/afbbd4。 –

+0

這也適用於MySQL服務器版本5.6.24和phpMyAdmin 4.4.6.1 – Jigar

回答

1

在早期版本的MySQL,你可以只聲明它NOT NULL

If an ENUM column is declared to permit NULL, the NULL value is a legal value for the column, and the default value is NULL. If an ENUM column is declared NOT NULL, its default value is the first element of the list of permitted values.

(從here。)

第一個值'off'將用於您的情況。