1. 實驗環境
ubuntu14.4 + django1.9.7
2. 問題描述
在配置完數據庫mysite/settings.py后,通常需要運行
python manage.py syncdb
為數據庫中每個應用建立一個數據庫表。
然而如果你安裝的Django Version >= 1.9,那么會出現如下問題:
gzxultra@gzxultraPC:~/django_try/mysite$ python manage.py syncdbUnknown command: 'syncdb'Type 'manage.py help' for usage.gzxultra@gzxultraPC:~/django_try/mysite$ python manage.py syncdbpython manage.py syncdbUnknown command: 'syncdbpython'Type 'manage.py help' for usage.
3. 解決方法
在stackoverflow上找到原因和解決方法:
syncdb is deprecated because of the migration system.
Now you can log your changes using makemigrations. This transforms your model changes into python code to make them deployable to another databases.
After you created the migrations you have to apply them: migrate.
So instead of using syncdb you should use makemigrations and then migrate.
簡言之:在Django 1.9及未來的版本種使用migrate代替syscdb.
./manage.py migrate