问题
I am trying to edit the fields of one of my objects in the Django admin site, I also have a Cloudinary image field in my model. The issue is, anytime I try to make an edit to one of the CharField
s of my object, I get the error:
value too long for type character varying(100)
which I later found out that every time I finish my edits and I am trying to save, it looks for a new image to replace the current image of my imagefile
even though I did not touch my imagefile
, thus it returns an empty image URL string like this:
But the current image URLworks fine and displays when clicked like this:
I just want to know if I am doing something wrong, why does it look for a new image URL every time I click save?
This is 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', max_length=512, null=False, default =
'https://res.cloudinary.com/firslovetema/image/upload/v1566807474/h1psyutzptxlnhuk8uyr.png')
def __str__(self):
return str(self.imagefile)
This is a follow up question to my previous question which can be found here:
value too long for type character varying(100)
回答1:
Django saves all attributes, not just the ones you've changed, when you save an object.
The Cloudinary library hard-codes max_length to 255, so
- your
max_length=512
doesn't do anything, and - you shouldn't be seeing an error about
VARCHAR(100)
on that field.
Are you sure that all of your migrations have been applied on Heroku? Try running
heroku run python manage.py migrate
来源:https://stackoverflow.com/questions/57996831/django-admin-site-does-not-pick-current-image-url