South忽略了Python / Django中字段默认值的变化 [英] South ignores change in field default value in Python / Django

查看:124
本文介绍了South忽略了Python / Django中字段默认值的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么南方不能识别Python模型中的默认字段值的更改?例如,使用以下迁移的现有模型:

Why does South not recognize changes in default field values in Python models? For example, take this existing model that is migrated with south:

class MyFamily(models.Model):
    family_size = models.IntegerField(verbose_name="What is your family size?", default=2)

,我想将默认值从2更改为4。但是,在模拟模块时,南方报告:

Now, I'd like to change the default value from two to four. However, when schemamigrating the module, South reports:

python manage.py schemamigration family --auto change_default_from_two_to_four_for_size

Running migrations for family:
- Nothing to migrate.
    - Loading initial data for family.

我可以手动更新初始迁移,并使用SQL直接更新该字段,但这是一个疼痛。有没有一个南方的命令我还没有发现可以识别默认的变化?

I could manually update the initial migration, and use the SQL to directly update the field, but that's a pain. Is there a South command I haven't found that recognizes the change in the default?

谢谢!

推荐答案

南方将不会更新现有列的默认值,因为只有在将新列添加到非空表时,他才是重要的。

South won't update the default value for existing columns, because it matters for him only when adding a new column to a non empty table. The django orm will handle writing the new default value to new rows before hitting the database.

如果你会工作,那么 django orm 将会处理在新的数据库之前写新的默认值在数据库外从 django orm ,您必须手动更新。

If you will work on the database from outside django orm, you have to update it manually.

更多说明 south / db.add_column

这篇关于South忽略了Python / Django中字段默认值的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆