MySql数组类型和默认值
我需要添加这样的默认值字段MySql数组类型和默认值,mysql,Mysql,我需要添加这样的默认值字段 `setting_notification` = 'a:2:{s:19:"other_notifications";i:1;s:21:"message_notifications";i:0;}' ALTER TABLE app_users ADD setting_notification tinytext COLLATE utf8_unicode_ci NOT NULL COMMENT '(DC2Type:array)' ALTER TABLE app_user
`setting_notification` = 'a:2:{s:19:"other_notifications";i:1;s:21:"message_notifications";i:0;}'
ALTER TABLE app_users ADD setting_notification tinytext COLLATE utf8_unicode_ci NOT NULL COMMENT '(DC2Type:array)'
ALTER TABLE app_users
ADD setting_notification tinytext
DEFAULT "a:2:{s:19:\"other_notifications\";i:1;s:21:\"message_notifications\";i:0;}"
COLLATE utf8_unicode_ci
NOT NULL COMMENT '(DC2Type:array)'
你怎么能做到这一点
我试试这个
ALTER TABLE app_users
ADD setting_notification LONGTEXT CHARACTER SET utf8
DEFAULT 'a:2:{s:19:"other_notifications";i:1;s:21:"message_notifications";i:0;}'
COMMENT '(DC2Type:array)'
并且有错误
[Err] 1101 - BLOB, TEXT, GEOMETRY or JSON column 'setting_notification' can't have a default value
试着这样做
`setting_notification` = 'a:2:{s:19:"other_notifications";i:1;s:21:"message_notifications";i:0;}'
ALTER TABLE app_users ADD setting_notification tinytext COLLATE utf8_unicode_ci NOT NULL COMMENT '(DC2Type:array)'
ALTER TABLE app_users
ADD setting_notification tinytext
DEFAULT "a:2:{s:19:\"other_notifications\";i:1;s:21:\"message_notifications\";i:0;}"
COLLATE utf8_unicode_ci
NOT NULL COMMENT '(DC2Type:array)'
还有错误吗
[Err] 1101 - BLOB, TEXT, GEOMETRY or JSON column 'setting_notification' can't have a default value
sql版本
mysql> SELECT VERSION();
+-------------------------+
| VERSION() |
+-------------------------+
| 5.7.16-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0,01 sec)
可以添加默认值。为什么使用tinytext而不是varchar
ALTER TABLE app_users ADD setting_notification varchar(255) DEFAULT "a:2:{s:19:\"other_notifications\";i:1;s:21:\"message_notifications\";i:0;}" COLLATE utf8_unicode_ci NOT NULL COMMENT '(DC2Type:array)'
可以添加默认值。为什么使用tinytext而不是varchar
ALTER TABLE app_users ADD setting_notification varchar(255) DEFAULT "a:2:{s:19:\"other_notifications\";i:1;s:21:\"message_notifications\";i:0;}" COLLATE utf8_unicode_ci NOT NULL COMMENT '(DC2Type:array)'
[Err]1101-BLOB、TEXT、GEOMETRY或JSON列“setting\u notification”不能有默认值
是否有任何理由将tinytext用作数据类型?使用varchar应该没问题。altertableapp\u用户添加设置\u notification varchar DEFAULT“a:2:{s:19:\“other\u notifications\”i:1;s:21:\“message\u notifications\”i:0;}“COLLATE utf8\u unicode\u ci NOT NULL COMMENT”(DC2Type:array)
[Err]1064-您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解可在“默认”附近使用的正确语法a:2:{s:19:\“其他通知”i:1;s:21:\“消息通知”i:'在第15行
我为varchar数据类型添加了一个长度。但我不知道它应该有多长。请调整此长度。[Err]1101-BLOB、TEXT、GEOMETRY或JSON列“setting\u notification”不能有默认值
是否有任何理由使用tinytext作为数据类型?使用varchar,您应该可以。ALTER TABLE app\u用户添加setting\u notification varchar default“a:2:{s:19:\”other\u notifications\“i:1;s:21:\”message\u notifications\“i:0;”“整理utf8\u unicode\u ci NOT NULL COMMENT'(DC2Type:array)
[Err]1064-您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以获取接近“默认”的正确语法a:2:{s:19:\“其他通知”;i:1;s:21:\“消息通知”\“i:'在第15行
我给varchar数据类型添加了一个长度。但我不知道它应该有多长。请调整这个长度。mysql版本是什么?mysql>选择版本();+--------------------------------------+-----------------------------+|版本()
mysql的版本是什么?mysql>选择版本();+-------------------------------------++++------------++++------------5.7.16-0ubuntu0.16.04.1+-------------------------------------+1行(0.01秒)