MySQL 如何解决因列问题而截断的数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38049942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to solve Data truncated for column issue
提问by Firefog
It works on localhost but not in cpanel How can I get rid from this error-
它适用于 localhost 但不适用于 cpanel 我怎样才能摆脱这个错误-
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'connectionMethod' at row 1
here is the MySQL code to create the table:
这是创建表的 MySQL 代码:
DROP TABLE IF EXISTS `file_server`;
CREATE TABLE `file_server` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`serverLabel` varchar(100) NOT NULL,
`serverType` enum('remote','local') DEFAULT NULL,
`ipAddress` varchar(15) NOT NULL,
`connectionMethod` enum('ftp') NOT NULL DEFAULT 'ftp',
`ftpPort` int(11) NOT NULL DEFAULT '21',
`ftpUsername` varchar(50) NOT NULL,
`ftpPassword` varchar(50) DEFAULT NULL,
`statusId` int(11) NOT NULL DEFAULT '1',
`storagePath` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `statusId` (`statusId`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
回答by Blank
Try to change (line 1298 in your script)
尝试更改(脚本中的第 1298 行)
`INSERT INTO `file_server` VALUES ('1', 'Local Default', 'local', '', '', '0', '', null, '2', null);`
to
到
`INSERT INTO `file_server` VALUES ('1', 'Local Default', 'local', '', 'ftp', '0', '', null, '2', null);`
One more thing if your column name is enum then in that case if u also have specified the default value then you need not to specify or give that column any values.
还有一件事,如果您的列名是 enum,那么在这种情况下,如果您还指定了默认值,那么您无需指定或为该列提供任何值。
回答by Aarush Aggarwal
In this case you need to change the query as follow:-
在这种情况下,您需要按如下方式更改查询:-
INSERT INTO `file_server` (`serverLabel`,`serverType`,`ipAddress`,`ftpPort`,`ftpUsername`,`ftpPassword`,`statusId`,`storagePath`) VALUES ('Local Default', 'local', '', '0', '', null, '2', null);
OR
或者
If you need to insert values in all the columns then in that case you need to write the below query.
如果您需要在所有列中插入值,那么在这种情况下您需要编写以下查询。
INSERT INTO `file_server` VALUES ('6', 'Local Default', 'local', '', 'ftp', '0', '', NULL, '2', NULL);