设计 models 模型
from django.db import models
# 积分信息
class Credits(models.Model):
user = models.ForeignKey(Visitors,on_delete=models.CASCADE,primary_key=True)
credits_total = models.IntegerField('总积分',default=0)
credits_buy = models.IntegerField('购买的积分',default=0)
time_credits_buy = models.DateTimeField('购买的工夫',auto_now_add=True)
credits_before_day = models.IntegerField('前一天签到的积分',default=0)
time_sign_before_day = models.DateTimeField('前一天签到的工夫',default=None)
class Meta():
# credits, 为数据库中的表名
db_table = 'credits'
python manage.py makemigrations
python manage.py migrate
Django 主动生成 models
如果数据库表曾经存在,执行命令,能够主动生成 Models 模型,实现 models 与数据表的映射
python manage.py inspectdb > tools/models.py