======================= 大爽歌作,made by big shuang =======================
三 常用命令和常见问题
1-常用命令:
新建项目:
django-admin startproject project_name
django 新建app
python manage.py startapp my_app
建立(更新)数据库
django 1.9版本及之前
python manage.py syncdb
django 1.9版本之后
python manage.py makemigrations
python manage.py migrate
创建超级用户(用于登录admin页面)
python manage.py createsuperuser
补充:创建超级用户时密码要求为:8位以上的数字+字母组合。django会自动检验,不符合时输出:
This password is too short. It must contain at least 8 characters.
This password is too common.
This password is entirely numeric.
使用交互式命令行测试代码
python manage.py shell
可通过这个方法操作数据库,详见:playing-with-the-api
2-常见报错:
- OperationalError at /admin/sites/site/add/
no such table: django_site
原因:出现这个报错,往往是INSTALLED_APPS添加了新的应用,但是没有更新数据库
解决方法:需要执行更新数据库操作