DJango 1.6 model.BinaryField导致TypeError

时间:2013-11-19 20:26:09

标签: python django postgresql

我使用DJango 1.6和python 2.7创建了一个类模型,如下所示:

class Company(models.Model):
        Name = models.CharField(max_length=150)
        PhoneNumber = models.CharField(max_length=20)
        Email = models.EmailField
        CompanyLogo = models.BinaryField

尝试使用python manage.py sql fetch创建代表sql导致错误:

File "/usr/local/lib/python2.7/dist-packages/Django-1.6-py2.7.egg/django/db/models/base.py", line 264, in add_to_class
    value.contribute_to_class(cls, name)
TypeError: Error when calling the metaclass bases
    unbound method contribute_to_class() must be called with BinaryField instance as first argument (got ModelBase instance instead)

postgresql数据库中的相应字段是bytea

类型

1 个答案:

答案 0 :(得分:1)

EmailFieldBinaryField都缺少()更改要编写的类,这样就解决了问题

class Company(models.Model):
        Name = models.CharField(max_length=150)
        PhoneNumber = models.CharField(max_length=20)
        Email = models.EmailField()
        CompanyLogo = models.BinaryField()