问题
I've read nearly all other posts with the same error and can't seem to find a proper solution.
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)
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
to:
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.
Updating my my.cnf.bak file wasnt enough, nor was making the CharField max_length to 65535. What else can I try?
回答1:
You need to use a TextField
. The max_length
of a CharField
should be set to 255 or less to avoid issues with DBs that store it as VARCHAR
.
https://docs.djangoproject.com/en/1.10/ref/databases/#character-fields
回答2:
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.
来源:https://stackoverflow.com/questions/39418063/dataerror-1406-data-too-long-for-column-name-at-row-1