gpt4 book ai didi

php - MySQL:使用枚举的默认值创建表错误

转载 作者:行者123 更新时间:2023-11-29 02:54:37 25 4
gpt4 key购买 nike

当我在 phpMyAdmin 中创建表时,我收到此错误:

#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 */;

最佳答案

在早期版本的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' 将用于您的情况。

关于php - MySQL:使用枚举的默认值创建表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32027664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com