Django-配置mysql

注意:需要在项目中安装mysqlclient包

setting文件数据库相关修改:

python 复制代码
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mysite3',
        'USER': 'root',
        'PASSWORD': 'bai12345',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

什么是模型?:

ORM框架:

注册app需要在setting中添加:

python 复制代码
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'music',
    'news',
    'sport',
    'bookstore'
]
python 复制代码
from django.db import models


# Create your models here.
class Book(models.Model):
    title = models.CharField("书名", max_length=100)
    author = models.DecimalField('价格', max_digits=10, decimal_places=2)

执行后结果: 生成的表名为app名_小写类名

相关推荐
瞎某某Blinder4 小时前
DFT学习记录[4] 电子和空穴的有效质量计算全流程
python·学习
c***03234 小时前
MySQL 启动失败 (code=exited, status=1FAILURE) 异常解决方案
数据库·mysql
ritxgt0064 小时前
MySQL 数据增删改查
android·数据库·mysql
Liue612312315 小时前
基于YOLO11-C3k2-Faster-CGLU的路面落叶检测与识别系统实现
python
t***44235 小时前
mysql之数字函数
数据库·mysql
zlpzpl5 小时前
MySQL 的 INSERT(插入数据)详解
android·数据库·mysql
~央千澈~6 小时前
抖音弹幕游戏开发之第8集:pyautogui基础 - 模拟键盘操作·优雅草云桧·卓伊凡
网络·python·websocket·网络协议
爱考证的小刘6 小时前
Oracle OCP、MySQL OCP数据库证书怎么选?
mysql·oracle·oracle数据库·oracle认证·mysql自学·mysql题库·oracle学习
占疏6 小时前
列表分成指定的份数
python
u***35746 小时前
MySQL ——数据的增删改查
数据库·mysql