DataError: (1406, Data too long for column name at row 1)

2024/5/20 13:06:48

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_itemsexisting_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?

Answer

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

https://en.xdnf.cn/q/73186.html

Related Q&A

Continued Fractions Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 7…

Spark: equivelant of zipwithindex in dataframe

Assuming I am having the following dataframe:dummy_data = [(a,1),(b,25),(c,3),(d,8),(e,1)] df = sc.parallelize(dummy_data).toDF([letter,number])And i want to create the following dataframe: [(a,0),(b,2…

How to find list comprehension in python code

I want to find a list comprehension in python source code, for that I tried to use Pygments, but it didnt find the way to do that. To be more specific, I want to do a function that recognize all the po…

Save XLSX file to a specified location using OpenPyXL

Im having an issue saving my file to a certain location on my Raspberry PI (Raspbian) computer. Im wanting the XLSX file to be saved directly to my desktop rather than the folder holding the Python Sc…

Pandas read csv dateint columns to datetime

Im new to both StackOverflow and pandas. I am trying to read in a large CSV file with stock market bin data in the following format:date,time,open,high,low,close,volume,splits,earnings,dividends,sym 20…

Pydantic - Dynamically create a model with multiple base classes?

From the pydantic docs I understand this: import pydanticclass User(pydantic.BaseModel):id: intname: strclass Student(pydantic.BaseModel):semester: int# this works as expected class Student_User(User, …

Handling nested elements with Python lxml

Given the simple XML data below:<book><title>My First Book</title><abstract><para>First paragraph of the abstract</para><para>Second paragraph of the abstract&…

Easiest way to plot data on country map with python

Could not delete question. Please refer to question: Shade states of a country according to dictionary values with Basemap I want to plot data (number of sick people for a certain year) on each state o…

How to resize QMainWindow after removing all DockWidgets?

I’m trying to make an application consisting of a QMainWindow, the central widget of which is a QToolBar (it may not be usual, but for my purpose the toolbar’s well suited). Docks are allowed below o…

Python: sorting a list by column [duplicate]

This question already has answers here:How to sort a list/tuple of lists/tuples by the element at a given index(11 answers)Closed 8 years ago.How can I sort a list-of-lists by "column", i.e. …