终端操作:
python manage.py startapp accounts
再这里面编写ORM模型代码.
class User(models.Model):
""" 用户模型 """
name = models.CharField('姓名', max_length=64)
sex = models.CharField('性别', max_length=1, choices=(
('1', '帅哥'),
('0', '美女'),
), default='1')
age = models.PositiveIntegerField('年龄')
username = models.CharField('用户名', max_length=64, unique=True)
password = models.CharField('密码', max_length=256)
remark = models.CharField('备注', max_length=64, null=True, blank=True)
created_at = models.DateTimeField('注册时间', auto_now_add=True)
updated_at = models.DateTimeField('最后修改时间', auto_now=True)
关联模型同步:
1.python manage.py check:
2.python manage.py makemigrations:
3.:python manage.py migrate:
查看命令: 终端> python manage.py
H:\djangoday2>python manage.py
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[auth]
changepassword
createsuperuser
[contenttypes]
remove_stale_contenttypes
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
[sessions]
clearsessions
[staticfiles]
collectstatic
findstatic
runserver
新增选项后:
重新执行 python manage.py makemigrations 会更新数据库项
再次执行:python manage.py migrate 同步到数据库