繁体   English   中英

Postgres如何存储django choice_fields-获取关系的列“类型”不存在错误

[英]How does postgres store django choice_fields - getting column “type” of relation does not exist error

我有一个带有选择字段的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 /关系“ place_thing”的列“类型”中得到了DatabaseError

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

为什么在同步或迁移数据库时未添加类型字段?

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

有人可以向我解释Thing类将由数据库创建什么吗?

谢谢

凯蒂

我最终使用

ALTER TABLE table_name添加列类型varchar(30);

这有效

我想已经创建了TYPE_CHOICES列

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM