配置
数据库
默认sqlite,
支持Mysql,postgresql,oracle
更改时区
查看表结构
.schema
(SQLite),
display the tables Django created.
新建Models
models原始文件
from django.db import models # Create your models here. class Qusetion(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): question_text=models.ForeignKey(Qusetion,on_delete=models.CASCADE) choice_text=models.CharFiled(max_length=200) votes_text=models.ForeignKey(default=0)
activating models
The sqlmigrate
command takes migration names and returns their SQL:
if you’re interested, you can also run python manage.py check; this checks for any problems in your project without making migrations or touching the database.
同步所有改变
the three-step guide to making model changes
- Change your models (in
models.py
). - Run
python manage.py makemigrations
to create migrations for those changes - Run
python manage.py migrate
to apply those changes to the database.
Playing with the API
manage.py shell
修改后再编译
Question----Qusetion !!!!!
在model中添加__str__methonds
Django Admin
manage.py createsuperuser
http://127.0.0.1:8080/admin/login/?next=/admin/
127.0.0.1:8080/admin
django.contrib.auth
, the authentication framework shipped by Django.