64👍
By specifying the column as VARCHAR(500)
you’ve set an explicit 500 character limit. You might not have done this yourself explicitly, but Django has done it for you somewhere. Telling you where is hard when you haven’t shown your model, the full error text, or the query that produced the error.
If you don’t want one, use an unqualified VARCHAR
, or use the TEXT
type.
varchar
and text
are limited in length only by the system limits on column size – about 1GB – and by your memory. However, adding a length-qualifier to varchar
sets a smaller limit manually. All of the following are largely equivalent:
column_name VARCHAR(500)
column_name VARCHAR CHECK (length(column_name) <= 500)
column_name TEXT CHECK (length(column_name) <= 500)
The only differences are in how database metadata is reported and which SQLSTATE is raised when the constraint is violated.
The length constraint is not generally obeyed in prepared statement parameters, function calls, etc, as shown:
regress=> \x
Expanded display is on.
regress=> PREPARE t2(varchar(500)) AS SELECT $1;
PREPARE
regress=> EXECUTE t2( repeat('x',601) );
-[ RECORD 1 ]-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
?column? | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
and in explicit casts it result in truncation:
regress=> SELECT repeat('x',501)::varchar(1);
-[ RECORD 1 ]
repeat | x
so I think you are using a VARCHAR(500)
column, and you’re looking at the wrong table or wrong instance of the database.
18👍
Character varying is different than text. Try running
ALTER TABLE product_product ALTER COLUMN code TYPE text;
That will change the column type to text, which is limited to some very large amount of data (you would probably never actually hit it.)
- [Django]-Django-social-auth django-registration and django-profiles — together
- [Django]-Does django with mongodb make migrations a thing of the past?
- [Django]-How do I include related model fields using Django Rest Framework?
7👍
We had this same issue. We solved it adding ‘length’ to entity attribute definition:
@Column(columnDefinition="text", length=10485760)
private String configFileXml = "";
- [Django]-Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)
- [Django]-Django admin: How to display the field marked as "editable=False" in the model?
- [Django]-How to make the foreign key field optional in Django model?
0👍
My problem was that I had Data in Table , So PostgreSQL don’t allow me to Make changes on my table !
change it to bigger value !
- [Django]-How do I package a python application to make it pip-installable?
- [Django]-Django – how to visualize signals and save overrides?
- [Django]-Unique fields that allow nulls in Django
0👍
I had the same problem. For my case, I went to pgAdmin>Schemas>Tables>blog_post
and then arrow click to ‘Colums’ then found the colum, character varing(25). right click and then properties, click ‘Definition. Finally I saw ‘Length/Precision’. I changed 25 to 50. That’s it. All good.
Once again, you need to change the size of your colum. go to pgAdmin>Schemas>Tables>(your app_model name)>Colums>(the colum you have problem)>Definition>Length
Change the size bigger. That’s it!!!
Good luck!
- [Django]-Django REST framework: non-model serializer
- [Django]-How to get the current URL within a Django template?
- [Django]-Import data from excel spreadsheet to django model
0👍
Adding to answer by Scot S here.
For Django ImageField or FileField,
adding max_length in the models.py worked for me.
img1 = models.ImageField(upload_to=user_directory_path,**max_length=500**)
- [Django]-Adding a user to a group in django
- [Django]-How do I use CSS in Django?
- [Django]-How to Unit test with different settings in Django?
0👍
In my case:
migrated a
CharField(max_length=1) to CharField(max_length=2)
then save some data.
Then I wanna migrate back
DB already have data like "sg"
inside.
just temporarily make them shorter will fix this error
Note if you have django-simple-history
installed. got there and change/delete data as well
The error log didn’t show what table/field, but the varying(1)
indicate where you should go.
- [Django]-Equivalent of PHP "echo something; exit();" with Python/Django?
- [Django]-Why does django's prefetch_related() only work with all() and not filter()?
- [Django]-Django error when installing Graphite – settings.DATABASES is improperly configured. Please supply the ENGINE value