当前位置:网站首页>Django框架MySQL数据库到models模型的映射关系
Django框架MySQL数据库到models模型的映射关系
2022-08-04 12:22:00 【lyudev】
设计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
边栏推荐
猜你喜欢
什么是 DevOps?看这一篇就够了!
LeetCode每日一题(858. Mirror Reflection)
ShanDong Multi-University Training #4 A、B、C、G
企业应当实施的5个云安全管理策略
免费翻译软件哪个好用
break与continue超详解!!!
来 TDengine 开发者大会,洞悉数据技术发展的未来趋势
UMA & Hong Kong Polytechnic & Ali propose SP-ViT to learn 2D space prior knowledge for visual Transformer!
MySQL - Explain详解
shell之循环语句(for、while、until)
随机推荐
Redis (1) installation and configuration
systemdd-dev病毒杀
Yolov5 test and train own dataset
【黑马早报】尚乘数科上市13天,市值超阿里;北大终止陈春花聘用合同;新东方花近200亿退学费和遣散费;张小泉75%产品贴牌代工...
缓存字符流
十一、网络规划设计
Flutter 使用 json_serializable 解析 JSON 支持泛型
MATLAB——图像分块
动手学深度学习_LeNet
如何过一个充满科技感的七夕?华为告诉你
聚焦数据来源、数据质量和模型性能构建小微企业信用画像
ECCV 2022 | 通往数据高效的Transformer目标检测器
Based on the BiLSTM regression forecast method
What is DevOps?Enough to read this one!
考研概率论与数理统计(知识点梳理)
推荐一款优秀的通用管理后台
yolo系列的Neck模块
电源测试之输出动态响应(Output Dynamic Response Test)
Yolov5 测试和训练自己的数据集
绩效考核带给员工的不能只是压力