数据错误:(1406,“第 1 行的列 'name' 的数据太长") [英] DataError: (1406, "Data too long for column 'name' at row 1")
问题描述
我已经阅读了几乎所有其他有相同错误的帖子,但似乎找不到合适的解决方案.
I've read nearly all other posts with the same error and can't seem to find a proper solution.
在我的 models.py 文件中,我有这个:
In my models.py file I have this:
class LetsSayCups(models.Model):
name = models.CharField(max_length=65535)
def __str__(self):
return str(self.name)
当我尝试将 aws mysql 数据加载到本地 mysql 服务器时出现此错误.我的models.py文件中的另一部分出现了问题,我能够解决它的方法是进入my.cnf.bak文件并从以下位置更改sql_mode:
I get this error when I try to load aws mysql data into my local mysql server. I had the issue occur for another part in my models.py file, and the way I was able to work around it was by going into the my.cnf.bak file and changing the sql_mode from:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
到:
sql_mode=''
它奏效了!!!直到后来我发现另一个错误.具体错误是这样的:
And it worked!!! Until later on I find another error. The specific error is something like this:
...
File "/Users/im_the_user/Desktop/my_company/my_project/load_items.py", line 122, in load_the_items
existing_cups = Cups.objects.get_or_create(name=cups)
...
django.db.utils.DataError: (1406, "Data too long for column 'name' at row 1")
以上......意味着事情发生在我遗漏在这之前/之后.
The above ... means things came before/after that I left out in this.
更新我的 my.cnf.bak 文件还不够,也没有将 CharField max_length 设置为 65535.我还能尝试什么?
Updating my my.cnf.bak file wasnt enough, nor was making the CharField max_length to 65535. What else can I try?
推荐答案
我发现 my.cfn.bak 只是一个备份文件.我不确定第一个问题是如何工作的,但是当我将文件重命名为 my.cfn 时,我的问题就解决了.
I found out that my.cfn.bak is only a backup file. I'm not sure how it worked for the first issue, but when I renamed the file to my.cfn my problem was resolved.
这篇关于数据错误:(1406,“第 1 行的列 'name' 的数据太长")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!