2. Create a new django project xynet

1. Environment Configuration

1.MySQL5.7

Still have to select 5.7, select 8..0 version, when deployed to the Ubuntu project, really pit to death.

MySQL5.7.25.0 Download: https: //dev.mysql.com/downloads/file/ id = 482771?

If MySQL8.0 later version installed on the computer before, you need to uninstall clean install MySQL5.7

Uninstall MySQL8.0 Tutorial: https: //jingyan.baidu.com/article/ca41422f0d42701eae99edb2.html

Installation MySQL5.7 the most hassle free way is to have the next step, all of them select the default settings on it.

2.Python3.6

Computer installation is python3.7.2, but the default installed on the server to python3 currently only 3.6, it must first uninstall the computer's python3.7, change the installation python3..6

How to completely uninstall python URL: https: //jingyan.baidu.com/article/4dc408487d1f11c8d946f1b1.html

python Download:

https://www.python.org/downloads/windows/

2. Use Software

1.IDE: Pycharm

2.Navicat

3.Xshell6

4.FileZilla

3. New Database xynet

 

show databases; // View all databases 
create database xynet default character set utf8 collate utf8_general_ci; // create a database xynet, because the Chinese have created a field in the data table, so to add a default

 

 

 

 

 

It is possible to report the error and resolve:

https://blog.csdn.net/weixin_43744799/article/details/85388272

4. New Project

1. Select New django project using pycharm

Look at django version, select 2.0

 

 

 2.连接MySQL数据

1.在settings.py中修改与数据库相关配置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'xynet',
        'USER':'root',
        'PASSWORD':'你的mysql密码',
        'HOST':'127.0.0.1',
        "OPTIONS":{"init_command":"SET default_storage_engine=INNODB;"}#第三方登录功能必须加上
    }
}

 

 

 

 

2.安装PyMYSQL

pip install PyMYSQL

3.在xynet/__init__.py中加入代码

import pymysql
pymysql.install_as_MySQLdb()

4.在终端执行数据更新命令,生成数据表

python manage.py makemigrations
python manage.py migrate

 

5.在pycharm中可视化管理数据库

1.点击左边的Database→点击“+”→选择Data Source→选择MySQL

 

 2.输入MySQL数据库用户root、MySQL数据库密码、要连接的数据库xynet,以及连接URL代码:

jdbc:mysql://localhost:3306/xynet?serverTimezone=UTC

然后点击测试连接按钮【Test Connection】

 

 3.即可直接对数据库进行管理

 

Guess you like

Origin www.cnblogs.com/xuepangzi/p/12299378.html