有趣的DatabaseError

时间:2013-02-13 03:04:26

标签: postgresql django-models

任何人都可以告诉我为什么在下面保存这个模型时我得到这个消息我已经环顾四周,发现有类似问题但有很多解决方案的人。

Exception Type:     DatabaseError
Exception Value: value too long for type character varying(10)
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py in execute, line 52


class Stylesheet(models.Model): 
    text_color = models.CharField(max_length = 50,default = '#000')
    a_visited = models.CharField(max_length = 50,default = '#000')
    background = models.CharField(max_length = 50,default = '#000')
    content_background_color = models.CharField(max_length = 50,default= '#000')
    nav_color = models.CharField(max_length = 50,default = '#000')
    nav_background = models.CharField(max_length = 50,default = '#000')
    nav_gradient_start = models.CharField(max_length = 50,default = '#000')
    nav_gradient_end = models.CharField(max_length = 50,default = '#000')
    nav_a_color = models.CharField(max_length = 50,default = '#000')
    nav_a_hover_color = models.CharField(max_length = 50,default = '#000')
    nav_a_hover_background = models.CharField(max_length = 50,default = '#000')
    nav_a_hover_gradient_start = models.CharField(max_length = 50,default = '#000')
    nav_a_hover_gradient_end = models.CharField(max_length = 50,default = '#000')
    slug = models.SlugField(max_length = 255,blank=True,null = True,editable=False)

    class Meta:
            db_table = 'stylesheet'
            verbose_name = 'Style sheet'
            verbose_name_plural = 'Style sheets'

    def __unicode__(self):
            return self.slug

    def save(self):                   
            super(Stylesheet, self).save()

1 个答案:

答案 0 :(得分:1)

你的申请中的第52行是哪一行?

问题似乎是您在数据库字段上设置了字符数限制10,并且您尝试将其传递给大于10的值

有关详情,请参阅此SO问题Strange PostgreSQL "value too long for type character varying(500)"