更改Django模型列默认使用南 [英] Change Django model column default using South

查看:130
本文介绍了更改Django模型列默认使用南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个模型字段,我想更改默认值,用于前进。我不需要以前的记录。只需新的记录。



我需要为此进行迁移,或者只是更改模型?



旧字段详细信息:

  background_style = models.CharField(max_length = 1,choices = BACKGROUND_STYLE,default = BackgroundStyleCode.CENTERED)

新字段详细信息:

 code> background_style = models.CharField(max_length = 1,choices = BACKGROUND_STYLE,default = BackgroundStyleCode.STRETCHED)

(型号为Page)

解决方案

您应该运行迁移。每当你改变一个模型,无论多么微不足道,你应该创建一个模式迁移,这样你可以向后移动到任何时间点,没有任何魔术的修改。


I'm using South with a Postgresql DB for a Django project.

There is a model field that I'd like to change the default value for going forward. I dont need previous records effected. Just new records.

Do I need to do a migration for this, or just change the model?

OLD FIELD DETAIL:

background_style = models.CharField(max_length=1, choices=BACKGROUND_STYLE, default=BackgroundStyleCode.CENTERED)

NEW FIELD DETAIL:

background_style = models.CharField(max_length=1, choices=BACKGROUND_STYLE, default=BackgroundStyleCode.STRETCHED)

(model name is "Page")

解决方案

You should run a migration. Any time you make a change to a model, no matter how insignificant, you should create a schema migration so that you can move backwards and forwards to any point in time without any "magic" edits.

这篇关于更改Django模型列默认使用南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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