django south 使用备忘

有些东西使用不熟悉的话总会忘记怎么使用的 。所以还在博客上记录下来比较好。

1 \安装south :方法见官网

2、在settings.py 加入 south APP。

3、 python manage.py  schemamigration  account --initial (account 是app 名)

4、python manage.py  schemamigration  account --auto

5、试着做一次 migrate:

python manage.py migrate account --fake
Running migrations for account:
- Migrating forwards to 0001_initial.
> account:0001_initial
(faked)

6、试着在models.py 里新增一个字段

python manage.py  schemamigration  account --auto

7、python manage.py migrate [appname] 

 

我遇到一个问题,记录下来:

我在models.py 里新增了一个models :Answer 

我在article models.py 里新加了一个model, 
然后想用south 生成,结果如下所示: 

ubuntu@yee:~/ndis$ python manage.py schemamigration article --auto 
+ Added model article.Answers 
Created 0002_auto__add_answers.py. You can now apply this migration with: ./manage.py migrate article 

ubuntu@yee:~/ndis$ python manage.py migrate article 
Running migrations for article: 
- Nothing to migrate. 
- Loading initial data for article. 
No fixtures found. 

ubuntu@yee:~/ndis$ python manage.py migrate article 0002 
- Soft matched migration 0002 to 0002_auto__add_answers. 
Running migrations for article: 
- Nothing to migrate. 
- Loading initial data for article. 
No fixtures found. 

 

可以看到没有生成我想要的表啊?怎么办呢?

python manage.py schemamigration article 0001 --empty 
python manage.py schemamigration article --initial 
+ Added model article.Article 
+ Added model article.Answers  这个就是新加的model
Created 0003_initial.py. You can now apply this migration with: ./manage.py migrate article 
python manage.py migrate article 0003 

我去查了一下数据库,发现表已经生成了。 汗~~~




posted @ 2012-11-13 15:19  notewo  阅读(297)  评论(0编辑  收藏  举报