【问题标题】:relation error on adding new model class添加新模型类时的关系错误
【发布时间】:2014-03-20 06:17:47
【问题描述】:

我在 models.py 文件中有 2 个模型类:

class Certificate(models.Model):
    comments = models.TextField(blank=True, default='')
    generic_certificate = models.ForeignKey(GenericCertificate, related_name='certificates_awarded')
    tag = models.ForeignKey('Tag', related_name='certificates_awarded', null=True, blank=True)


class GenericCertificate(CommonInfo):
    CERTIFICATE_TYPE = (('C', 'system created'),
                        ('U', 'user created'))

    certificate_icon = models.ImageField(upload_to='certificate/icons', default='defaults/certificate.png')
    certificate_type = models.CharField(choices=CERTIFICATE_TYPE, max_length=1, default='C')
    template = models.FileField(upload_to='certificate/generic_templates')

他们在 django admin 中工作正常,但是当我添加一个模型类时,它开始在点击通用证书选项时出现错误:包含操作:South Migration 和 syncdb 异常类型:ProgrammingError 异常值:
关系“certificates_genericcertificate”不存在 第 1 行:从“certificates_genericcertificate”中选择 COUNT(*)

在同一个models.py中新添加的模型类

class PositionCertificate(models.Model):
    rewardee = models.CharField(max_length=50, default = '0,0')
    org_logo = models.CharField(max_length=50, default = '0,0')
    tag_name = models.CharField(max_length=50, default = '0,0') 

如何消除此错误?为什么会出现这个错误?

【问题讨论】:

  • 你做过syncdb,架构迁移吗?

标签: django django-models django-south


【解决方案1】:

错误
relation "certificates_genericcertificate" does not exist 表示您的数据库中不存在“certificates_genericcertificate”关系。
请做

python manage.py syncdb

如果您使用的是 South,您可以使用

python manage.py 迁移

尝试使用这些命令,如果对您没有帮助,请删除您的表/数据库并使用 syncdb 重新创建表/数据库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 2013-02-20
    • 2021-12-08
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多