现在的位置: 首页 > 综合 > 正文

django中的south小记

2018年02月19日 ⁄ 综合 ⁄ 共 1029字 ⁄ 字号 评论关闭

1:south的安装:

首先申明下我的系统是window7.安装south前需要安装easy_install,可以去网上下载setuptools-0.6c11.win32-py2.7.exe,双击就可以了,前提是你已搭建好python和django环境.

然后在dos下转到python/script目录下,用easy_install South即可安装south了


2:south的使用:

这里south的使用主要针对是你已经将你的app,用syncdb同步到数据库了,但此时需要修改app的models.py 中相关字段,步骤如下:

(1)将south加到settings.py 的INSTALLED_APPS中,并syncdb到数据库.在数据库中会建立south_migrationhistory表,

(2)使用两个命令:

<1>python manage.py schemamigration appname --initial,它将在每个app的目录下创建migration目录和相应的文件

     <2>manage.py
migrate appname 0001 --fake,,该命令不会对数据库做任何操作,只是欺骗一下south,让它在south_migrationhistory表中添加一些记录以便于下次你想创造migration文件的时候所有东西都已搞定。

(3)修改你的models.py 

(4)使用两个命令:

<1>manage.py
migra
te  appname 0001_initial.py  --fake 这个命令的意思就是,
这个迁移命令先虚假执行, 在 south_migrationhistory  记录好, 0001_initial.py 这个迁移命令已经执行过了, 以后就不要再执行了

 
 <2>manage.py schemamigration appname --auto

(5)执行python
manage.py
migrations appname就okay了

 我只用到这一种情况,其他的还有很多情况暂没研究,详细见http://ddtcms.com/blog/archive/2012/12/27/66/use-south-migrate-django-project-database/,

最后想说的就是
貌似south中一直有个概念就是migrate 迁移,个人认为迁移的方向是将app中的models.py的表迁移到south_migrationhistory表上

哈哈~~~








抱歉!评论已关闭.