Django连接MySQL数据库(python3.6+Django2.0+虚拟运行环境)

1.首先pycharm创建python的虚拟运行环境

这里写图片描述

2.安装Django2.0

这里写图片描述

创建Django项目

这里写图片描述

3.安装mysqlclient,配置setting文件

拖入wheel文件,需要下载见另一篇博客

下载方法

这里写图片描述

pip安装

这里写图片描述

修改setting文件

这里写图片描述

此时数据库

这里写图片描述

4.执行迁移,测试运行

(venv) C:\Users\Administrator\PycharmProjects\mytest\sqltest>python manage.py migrate
System check identified some issues:

WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings in
to errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/2.0/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying sessions.0001_initial... OK

此时数据库

这里写图片描述

测试运行

这里写图片描述

5.创建后台用户,测试运行

(venv) C:\Users\Administrator\PycharmProjects\mytest\sqltest>python manage.py createsuperuser
Username (leave blank to use 'administrator'): admin
Email address: 16@qq.com
Password:
Password (again):
Superuser created successfully.

此时数据库

这里写图片描述

测试

这里写图片描述

结束

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值