[英]Mysql 1406 Data too long for column
I have a string containing more than 600 characters, where I want to Insert it in a column VARCHAR (255)
column我有一个包含超过 600 个字符的字符串,我想将它插入到
VARCHAR (255)
列中
I tested on two different databases:我在两个不同的数据库上进行了测试:
mysql 5.7.31-34-log
database, I ran into this exception:mysql 5.7.31-34-log
数据库,我遇到了这个异常:["@@sql_mode"]=> string(40) "STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION"
["@@sql_mode"]=> 字符串(40) "STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION"
mysql 5.7.19
database, the string is well registered into my database, but with a warning message: Level Code Messagemysql 5.7.19
数据库,该字符串已很好地注册到我的数据库中,但带有警告消息: Level Code Message["@@sql_mode"]=> string(0) ""
["@@sql_mode"]=> 字符串(0) ""
I would be grateful if someone could explain to me it is a good practice to disable strict mode, and does truncate remove a part of the string if exceeded?如果有人可以向我解释禁用严格模式是一个好习惯,我将不胜感激,如果超过,截断是否会删除字符串的一部分?
you cannot store 600 character in varchar(255) since It's allowing only 255 character.dependingvon your configuration data will be rejected or truncated after 255 character.您不能在 varchar(255) 中存储 600 个字符,因为它只允许 255 个字符。取决于您的配置数据将在 255 个字符后被拒绝或截断。 The version of MySql you are using allow way more that 255 for varchar data type.
您使用的 MySql 版本允许 varchar 数据类型超过 255。 please alter the column to extend the length.
请更改列以延长长度。 you may use varchar(600) for example.
例如,您可以使用 varchar(600)。
You can insert a 600 long string into a 255 long column.您可以将 600 长的字符串插入到 255 长的列中。 Change your VARCHAR(255) by TEXT and it will be ok.
通过 TEXT 更改您的 VARCHAR(255) 就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.