开启代码之旅 Launch With Code
1334 浏览 5 years, 11 months
8 Make changes to Django Models with South
版权声明: 转载请注明出处 http://www.codingsoho.com/安装south
pip install south
INSTALLED_APPS = (
'joins',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'south'
)
用south来控制joins的migration
python manage.py convert_to_south joins
这条命令会创建history和初始的migration
本地运行时,之前已有joins数据库,一个简单方法是直接删除joins/migrations,然后执行sync,将会从头执行
python manage.py syncdb
将会创建表 south_migrationhistory, joins_join
执行修改
python manage.py schemamigration joins –auto
migrate db
python manage.py migrate joins
https://github.com/codingforentrepreneurs/Guides/blob/master/all/using_south_in_django.md
1) Install south : pip install south, add south to settings.py in INSTALLED APPS
2) Ensure model is in sync in database
3) Covert the model to south with : python manage.py convert_to_south appname
4) Make changes to model (eg add new fields : ip_address = model.CharField(max_length=120
5) Run schemamigration : python manage.py schemamigration appname --auto
6) Run migrate : python mange.py migrate