DataError值太长,无法更改类型字符(100) [英] DataError value too long for type character varying(100)

查看:183
本文介绍了DataError值太长,无法更改类型字符(100)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Django的管理站点上对我的个人资料对象进行更改,但是当我单击保存时,在/ admin / profiles / profiles / 31 / change / value处出现错误DataError,对于类型字符变化来说,该错误太长了( 100)。奇怪的是,当我在本地对同一字段进行更改时,它起作用了,但是当我部署到Heroku时,它给了我 DataError。我的图片网址是对象中唯一的长字符串。旁注,由于数据非常小,我仍将sqlite3与Heroku一起使用。

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

我尝试将max_length设置为512。它仍然没有工作。

I have tried setting the max_length to 512. it still did not work.

我的models.py文件:

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)

完整错误日志:

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


推荐答案

我得到了答案,我没有生成并应用迁移来创建imagefile字段,我只需要在本地进行迁移,但是在提交了迁移文件后,我想使用以下方法在Heroku上进行迁移:

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

这篇关于DataError值太长,无法更改类型字符(100)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆