zoukankan      html  css  js  c++  java
  • Django配置MySQL数据库

    一、在settings.py中配置

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',  # 数据库引擎
            'NAME': 'django',              # 你要存储数据的库名,事先要创建之
            'USER': 'django',              # 数据库用户名
            'PASSWORD': 'django@123',         # 密码
            'HOST': 'localhost',            # 主机
            'PORT': '3306',                # 数据库使用的端口
        }
    }

     

    二、数据库迁移

    Python3不支持MySQLdb,可用pymysql代替。

    1.首先,在Python虚拟环境下安装pymysql:pip install pymysql。

    [root@python ~]# pip3 install pymysql
    #或者pip install pymysql                

    2.然后,在项目文件夹下的_init_.py添加如下代码即可。

    import pymysql
    pymysql.install_as_MySQLdb()

     

    3.再者,在Terminal中执行数据库迁移命令:

    python manage.py makemigrations
    python manage.py migrate
  • 相关阅读:
    Elasticsearch
    区块链 blockchain
    IM协议
    MQ,互联网架构解耦神器
    服务中的 API 网关(API Gateway)
    OSI七层与TCP/IP五层网络架构详解
    JQ input标签限制输入数字或字母
    c:forEach用法
    jquery在线引用
    JSONObject使用方法
  • 原文地址:https://www.cnblogs.com/sky-k/p/10399539.html
Copyright © 2011-2022 走看看