0%

django的数据管理插件south

django的数据管理插件south的使用经验

South is a tool to provide consistent, easy-to-use and database-agnostic migrations for Django applications.

下载地址:http://www.aeracode.org/releases/south/

文档地址:http://south.aeracode.org/docs/index.html

第一次使用:

1
2
python manage.py schemamigration youappname --initial 
python manage.py syncdb

#以后每次对models更改后,运行以下两条命令同步到数据库

1
2
python manage.py schemamigration youappname --auto     #检测对models的更改
python manage.py migrate youappnam #将更改反应到数据库(如果出现表已存在的错误,后面加 --fake)

对于一个已存在的项目(定义了models,创建了相应的数据库,保存了响应的数据),这时想要使用South替代原来的syncdb只需要一些简单的步骤:

同样INSTALL_APP里面添加south,然后

1
2
python manage.py syncdb  #syncdb已经被South更改,用来创建south_migrationhistory表
python manage.py convert_to_south youappname #在youappname目录下面创建migrations目录以及第一次迁移需要的0001_initial.py文件

以后在这个项目中就可以正常使用South了