django应用:south的使用

django自学教程:http://www.ziqiangxuetang.com/django/django-views-urls2.html
http://docs.30c.org/djangobook2/chapter10/

环境:python2.7.11 django 1.6 centos6.5 pip8.1.1 mysql 5.1.73 python-mysql1.2.5
安装django数据库管理工具south
pip install south
south的使用http://www.th7.cn/Program/Python/201408/263582.shtml
将juser纳入south管理,执行后,会在对应的juser目录下新建一个migration目录
python manage.py convert_to_south juser
如果 blog 这个 app 之前就创建过相关的表,可以用下面的来“假装”用 South 创建(伪创建,在改动 models.py 之前运行这个,注意如果改动了models.py,需要将其改回原来的再执行。否则相应的变动不会生效)
python manage.py migrate blog –fake
接着,当你对 Blog.models 做任何修改后,只要执行:
python manage.py schemamigration juser –auto
再执行
python manage.py migrate juser 数据表便会同步改变
注意:
假如改动了models.py后又执行了python manage.py convert_to_south juser,生成了migrations的目录,此时再执行python manage.py schemamigration juser –auto不会生效,需要将migrations的目录删除,改回原来的models.py后再convert_to_south

App ‘juser’ converted. Note that South assumed the application’s models matched the database
(i.e. you haven’t changed it since last syncdb); if you have, you should delete the juser/migrations directory, revert models.py so it matches the database, and try again
South对于字段的改名是先删除原来字段,然后添加新的字段。。。对于添加的新字段值会让你填一个默认值。

http://blog.csdn.net/watsy/article/details/11965019
http://www.cnblogs.com/BeginMan/p/3324774.html
http://www.cnblogs.com/BeginMan/p/3325897.html

你可能感兴趣的:(django,south)