Change Django model column default using South

僤鯓⒐⒋嵵緔 提交于 2019-12-10 21:27:36

问题


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")


回答1:


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.



来源:https://stackoverflow.com/questions/8558148/change-django-model-column-default-using-south

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!