"错误1406:1406:数据对于列而言太长"但这不应该吗? [英] "ERROR 1406: 1406: Data too long for column" but it shouldn't be?

查看:85
本文介绍了"错误1406:1406:数据对于列而言太长"但这不应该吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下表格结构:

DROP TABLE IF EXISTS `tblusers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tblusers` (
  `UserID` int(5) NOT NULL AUTO_INCREMENT,
  `ContactPersonID` int(5) NOT NULL,
  `NameOfUser` varchar(70) NOT NULL,
  `LegalForm` varchar(70) DEFAULT NULL,
  `Address` varchar(70) DEFAULT NULL,
  `City` varchar(50) DEFAULT NULL,
  `Postal` int(8) DEFAULT NULL,
  `Country` varchar(50) DEFAULT NULL,
  `VatNum` int(10) DEFAULT NULL,
  `Username` varchar(30) NOT NULL,
  `Password` varchar(20) NOT NULL,
  `Email` varchar(40) NOT NULL,
  `Website` varchar(40) DEFAULT NULL,
  `IsSeller` bit(1) DEFAULT NULL,
  `IsBuyer` bit(1) DEFAULT NULL,
  `IsAdmin` bit(1) DEFAULT NULL,
  `Description` text,
  PRIMARY KEY (`UserID`),
  KEY `ContactPersonID` (`ContactPersonID`),
  CONSTRAINT `tblusers_tblpersons` FOREIGN KEY (`ContactPersonID`) REFERENCES `tblpersons` (`PersonID`)
) ENGINE=InnoDB AUTO_INCREMENT=87 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

然后,一旦我从应用程序的UI创建用户,就必须手动设置第一个管理员,这是我唯一一次直接从数据库执行此操作的方法,其余所有操作都可以从用户界面(授予管理员权限):

Then once I create a user from the UI of my application, I have to manually set the very first admin, and this is the only time I am doing this directly from the DB, all the rest is envisioned to be done from the UI (granting admin privileges):

UPDATE `tblusers` SET `IsAdmin`='1' WHERE `UserID`='79';

但是我得到:

Operation failed: There was an error while applying the SQL script to the database.
Executing:
UPDATE `trace`.`tblusers` SET `IsAdmin`='1' WHERE `UserID`='79';

ERROR 1406: 1406: Data too long for column 'IsAdmin' at row 1
SQL Statement:
UPDATE `trace`.`tblusers` SET `IsAdmin`='1' WHERE `UserID`='79'

这没什么意义,因为我在其他机器上做的完全一样,而且它就像一个魅力.唯一的区别是,在这种情况下,我有mysql 5.7服务器,而在能正常工作的机器上有5.6版本.

Which doesn't make sense because I am doing the exact same thing on other machines and it works like a charm. The only difference is that in this scenario I have mysql 5.7 server whereas I have 5.6 versions on the machines that this does work.

我尝试了以下解决方案,但它没有为我工作.除此之外,my.ini文件在可以正常运行的5.6计算机中保持不变.

I tried the following solution but it didn't work for me. Besides that, the my.ini file is unchanged in the 5.6 machine where it does work.

降级到5.6是不可能的.请在这里找到一个真正的解决方案.

Downgrading to 5.6 is out of the question. I need a real solution here please.

推荐答案

isadmin是类型为bit的列,并且您要在其中存储类型为varchar的值,该值的大小大于bit.修改查询如下:-

isadmin is a column of type bit and you are storing a value of type varchar in it which is of larger size than bit. modify query as follows:-

UPDATE `tblusers` SET `IsAdmin`=b'1'  WHERE `UserID`='79';

这篇关于"错误1406:1406:数据对于列而言太长"但这不应该吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆