124๐
I can bet money you have a models.SlugField
without length set. The default length is 50 characters, most likely itโs not enough for your use case.
Change it to models.SlugField(max_length=255)
and migrate your database schema.
41๐
I also had this problem when using a filefield and was scratching my head for a while. Of course the default FileField instances are created with a 100 character limit.
https://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
- [Django]-How do I output HTML in a message in the new Django messages framework?
- [Django]-Backwards migration with Django South
- [Django]-Implementing Single Sign On (SSO) using Django
18๐
This is an error message from Postgres and not django.
You seem to have changed the length of the field in the models.py
, but that doesnโt change the database length which was created when you did a manage.py syncdb
.
You have to alter the length of the field in the database, directly.
- [Django]-How to get the value of a Django Model Field object
- [Django]-TemplateDoesNotExist โ Django Error
- [Django]-How can I access environment variables directly in a Django template?
5๐
Django 2.1
I encountered this problem while switching from sqlite3 to postgresql.
Remove the migration files in each appโs migrations folder except __init__.py
Then re-run migration
(venv)myapp$python manage.py makemigrations
(venv)myapp$python manage.py migrate
(venv)myapp$python manage.py runserver
- [Django]-Django optional URL parameters
- [Django]-How to access Django's field.choices?
- [Django]-Gunicorn Connection in Use: ('0.0.0.0', 5000)
2๐
I had a similar problem with django-autoslugfield
I was using a similar package and then switched over to django-autoslugfield
I was getting this error:
value too long for type character varying(50)
despite the fact that my models.py had:
slug = AutoSlugField(max_length=255, populate_from='name', unique=True)
and in my db the it the type was
character varying 255
once i remove max_length=255
from the field i.e.
slug = AutoSlugField(populate_from='name', unique=True)
then it worked fine
- [Django]-FileUploadParser doesn't get the file name
- [Django]-Django Celery โ Cannot connect to amqp://guest@127.0.0.8000:5672//
- [Django]-How would you create a 'manual' django migration?
2๐
i went through this same error. and when i made changes in the modele, i kept having the same error.
Here is how i fixed it.
It might be necessary to skip few migrations for the program to only use the migration where changes have been made for the CharField max_lenght.
for that you have to run
python manage.py showmigrations
to see which migrations have not been made.
then you skip them until you get to the last with the command
python manage.py migrate <app> 000_migration_number --fake
- [Django]-Jquery template tags conflict with Django template!
- [Django]-Django: manage.py does not print stack trace for errors
- [Django]-How to query Case-insensitive data in Django ORM?
1๐
I realize the question is already answered but for others that come here when looking for the error message:
In my case the problem was that my table name exceeded 50 characters. Apparently this is not allowed. Changing the table name solved the problem.
Read more here: https://code.djangoproject.com/ticket/18959
- [Django]-Inline Form Validation in Django
- [Django]-How to resize an ImageField image before saving it in python Django model
- [Django]-Is there a way to negate a boolean returned to variable?
1๐
Michael Samoylovโs answer pointed me in the right direction. I had the same error come up, except it was with a FileField.
Fields have a max_length, even if you have not explicitly set a max_length. Increase the value so that your data fits to avoid the error.
In my case, the data was too large to reasonably store in the database. I resorted to saving my file to disk, then saving the file path in the database.
- [Django]-How to use django-debug-toolbar on AJAX calls?
- [Django]-CSRF with Django, React+Redux using Axios
- [Django]-How to completely uninstall a Django app?
1๐
For the FileField and the ImageField, from the Django docs:
FileField instances are created in your database as varchar columns with a default max length of 100 characters. As with other fields, you can change the maximum length using the max_length argument.
- [Django]-Limit foreign key choices in select in an inline form in admin
- [Django]-Django: best practice way to get model from an instance of that model
- [Django]-Gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3> django
1๐
I had this problem when I wanted to set max_length
to a lower value on a FileField
.
Interestingly, the error message states value too long
but in my case the value was too short.
The solution was to set back the max_length
to its old value. Itโs quite weird that the migration couldnโt be done.
I also had to delete the wrongly generated migrations files and rerun python manage.py makemigrations
and python manage.py migrate
.
- [Django]-Running django tutorial tests fail โ No module named polls.tests
- [Django]-Can I have a Django model that has a foreign key reference to itself?
- [Django]-Rendering a value as text instead of field inside a Django Form
0๐
If itโs not SlugField
, FileField
, or any other field mentioned hereโscroll back to where the migration got stuck in the terminal. For me it was AddField
Good talk.
- [Django]-Explicitly set MySQL table storage engine using South and Django
- [Django]-In django do models have a default timestamp field?
- [Django]-How to group by AND aggregate with Django
0๐
First, try setting max_length to something reasonable on all applicable field types in your model.
For example: MyText = models.CharField(max_length=2000)
If you donโt set a max_length, your database might be applying a default max_length, shorter than the length of your input data, causing your value too long for type character
error.
If that doesnโt work and you started in SQLite and changed databases to PostgreSQL, the previous migrations from SQLite might be interfering with the new PostgreSQL migrations.
Go into the migrations folder for your project and delete the old migration files to get a fresh start. Then try makemigrations and migrate again ๐
- [Django]-OneToOneField() vs ForeignKey() in Django
- [Django]-How to refer to static files in my css files?
- [Django]-How to mix queryset results?
0๐
predefined fields in model.py creates the problem. Extend it to desired length, i think problem will be resolved.
- [Django]-Django rest framework โ filtering for serializer field
- [Django]-Django Queryset with filtering on reverse foreign key
- [Django]-Where can I find the error logs of nginx, using FastCGI and Django?
- [Django]-How to understand lazy function in Django utils functional module
- [Django]-STATIC_ROOT vs STATIC_URL in Django
- [Django]-Django 1.8 โ what's the difference between migrate and makemigrations?
-1๐
The value can be 100 or 25 or 17 whatever , the reason behind that is models , search where you have added that particular length(17,25) and you will get the bug ! ,
You are trying to impose a field length more than mentioned one.
This solved my issue , I hope it will help you too
- [Django]-How do you configure Django for simple development and deployment?
- [Django]-How to encode UTF8 filename for HTTP headers? (Python, Django)
- [Django]-Django โ iterate number in for loop of a template