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

版权声明:一起学习啊 https://blog.csdn.net/q1694222672/article/details/81532509

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: [email protected]
Password:
Password (again):
Superuser created successfully.

此时数据库

这里写图片描述

测试

这里写图片描述

结束

猜你喜欢

转载自blog.csdn.net/q1694222672/article/details/81532509