设计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