我有一个Django模型,使用了choices
属性。
COLOR_CHOICES = (
('R', 'Red'),
('B', 'Blue'),
)
class Toy(models.Model):
color = models.CharField(max_length=1, choices=COLOR_CHOICES)
我的代码已经在生产中了,现在我想添加额外的选项。
COLOR_CHOICES = (
('R', 'Red'),
('B', 'Blue'),
('G', 'Green'),
)
我该如何做?Django是否使用数据库约束来强制选择?我需要进行数据库迁移吗(我正在使用South)?还是Django仅在Python代码中强制执行选择限制,我只需要更改代码并重新启动即可?
谢谢!
MyModel.objects.filter(color="R").update(color="G")
- Bernhard Vallant