简体   繁体   English

在迁移Django / South上设置默认值?

[英]Set default value on migration Django/South?

Is Django 1.6 with South 0.8 going to set default value when I add a column with default value to existing data having the field described like this? 当我将具有default值的列添加到具有这样描述的字段的现有数据中时,带有South 0.8的Django 1.6会设置默认值吗?

gametype = models.PositiveSmallIntegerField(_('type of game'), 
                                            choices=CONST_TYPES, 
                                            default=CONST_TYPE_NORMAL, 
                                            null=True, blank=True)

I am worrying about having null=True at the same time with default specified 我担心同时将null=Truedefault指定

It depends on whether gametype is a new field or not. 这取决于游戏类型是否为新字段。

  1. If the gametype field is a new field, the migration will add that field to every model instance and use the default value. 如果gametype字段是一个新字段,则迁移会将该字段添加到每个模型实例并使用默认值。
  2. However, if the gametype field already existed and there are values in the database already, South shouldn't mess with them, even if they're NULL. 但是,如果gametype字段已经存在,并且数据库中已经有值,即使它们为NULL,South也不会弄乱它们。

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

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