【问题标题】:How does postgres store django choice_fields - getting column "type" of relation does not exist errorpostgres如何存储django choice_fields - 获取关系的列“类型”不存在错误
【发布时间】:2012-09-10 22:39:06
【问题描述】:

我有一个带有选择字段的 CharField 类型,如下所示:

class Thing(models.Model):
    def __unicode__(self):
        return self.name

    A = 'a'
    B = 'b'
    C = 'c'

    TYPE_CHOICES = (
        (A, 'a'),
        (B, 'b'),
        (C, 'c'),
    )
        ...
    type = models.CharField(max_length = 1, choices=TYPE_CHOICES)
        ...

现在,当我尝试访问页面添加/事物时,我在 /path/to/thing/add/ 处收到 DatabaseError 关系“place_thing”的列“类型”不存在

我检查了数据库(postgres),发现类型不是错误中所说的列。

为什么我同步或迁移数据库时没有添加类型字段?

如何在我的数据库 (postgres) 中创建“TYPE_CHOICES”和“type”列?

有人可以向我解释一下数据库会为 Thing 类创建什么吗?

谢谢

凯蒂

【问题讨论】:

    标签: database django postgresql django-models choicefield


    【解决方案1】:

    我最终使用了

    ALTER TABLE table_name ADD COLUMN type varchar(30);

    这成功了

    我猜 TYPE_CHOICES 列已经生成了

    谢谢

    【讨论】:

    猜你喜欢
    • 2016-07-05
    • 2019-08-02
    • 2020-04-09
    • 2022-03-29
    • 2016-04-11
    • 2021-04-14
    • 1970-01-01
    • 2015-06-22
    • 2014-11-07
    相关资源
    最近更新 更多