问题
I need to make changes to my profiles object at the admin site in Django, but when I click save, I get the error DataError at /admin/profiles/profiles/31/change/ value too long for type character varying(100). The weird thing is, it worked when I made changes to the same field locally, but when I deployed to Heroku, it gave me the 'DataError'. My image url is the only long string in my object. Side note, I am still using sqlite3 with Heroku because the data is very small.
Currently: http://res.cloudinary.com/firslovetema/image/upload/v1568570093/ypqiiwg5eq5uyd7oie6g
I have tried setting the max_length to 512. it still did not work.
my models.py file:
from django.db import models
from cloudinary.models import CloudinaryField
class profiles(models.Model):
firstname = models.CharField(max_length=120, default = 'null') #max_length=120
lastname = models.CharField(max_length=120, default = 'null')
gender = models.CharField(max_length=120, default = 'null')
dob = models.CharField(max_length=120, default = 'null')
callNumber = models.CharField(max_length=120, default = 'null')
whatsappNumber = models.CharField(max_length=120, default = 'null')
ministry = models.CharField(max_length=120, default = 'null')
centre = models.CharField(max_length=120, default = 'null')
campus = models.CharField(max_length=120, default = 'null')
hostel_address = models.CharField(max_length=120, default = 'null')
city = models.CharField(max_length=120, default = 'null')
qualification = models.CharField(max_length=120, default = 'null')
profession = models.CharField(max_length=120, default = 'null')
maritalStatus = models.CharField(max_length=120, default = 'null')
bacenta = models.CharField(max_length=120, default = 'null')
layschool = models.CharField(max_length=120, default = 'null')
imagefile = CloudinaryField('image', null=True, max_length=512, blank=True)
def __str__(self):
return str(self.imagefile)
Full error log:
DataError at /admin/profiles/profiles/31/change/
value too long for type character varying(100)
Request Method: POST
Request URL: https://ewuradjango.herokuapp.com/admin/profiles/profiles/31/change/
Django Version: 2.2.3
Exception Type: DataError
Exception Value:
value too long for type character varying(100)
Exception Location: /app/.heroku/python/lib/python3.7/site-
packages/django/db/backends/utils.py in _execute, line 84
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.7.1
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python37.zip',
'/app/.heroku/python/lib/python3.7',
'/app/.heroku/python/lib/python3.7/lib-dynload',
'/app/.heroku/python/lib/python3.7/site-packages']
Server time: Tue, 17 Sep 2019 11:31:39 +0000
回答1:
I got the answer, I had not generated and applied migrations to create the imagefile field, I only needed to makemigrations locally, but after commit the migration files I wanted to migrate on Heroku with:
heroku run python3 manage.py migrate
来源:https://stackoverflow.com/questions/57973619/dataerror-value-too-long-for-type-character-varying100