South 忽略 Python / Django 中字段默认值的更改

发布于 2024-11-08 10:56:42 字数 545 浏览 0 评论 0原文

为什么 South 无法识别 Python 模型中默认字段值的更改?例如,采用向南迁移的现有模型:

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

现在,我想将默认值从 2 更改为 4。然而,当对模块进行模式迁移时,South 报告说:

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 直接更新字段,但这很痛苦。是否有我未找到的 South 命令可以识别默认值的更改?

谢谢!

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)

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.

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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴随着你 2024-11-15 10:56:42

South 不会更新现有列的默认值,因为只有在向非空表添加新列时这对他才重要。 django orm 将在访问数据库之前将新的默认值写入新行。

如果您将从 django orm 外部处理数据库,则必须手动更新它。

更多说明south/db.add_column

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.

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

More explanations south/db.add_column

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文