工具版本:
python3.6.3
django1.9.8
安装工具
mkvirtualenv --python="C:\Python36\python.exe" mxonline (mxonline) C:\Users\user>pip install django==1.9.8 (mxonline) C:\Users\user>pip install pymysql
使用pycharm打开项目
修改数据库配置
1、在项目文件夹下的_init_.py中导入pymysq包
import pymysql pymysql.install_as_MySQLdb()
2、settings.py配置
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, ‘NAME‘: ‘mxonline‘, ‘USER‘: ‘mxonline‘, ‘PASSWORD‘: ‘123456‘, ‘HOST‘: ‘192.168.88.222‘, ‘PORT‘: 3306 }
创建数据库
create database mxonline; grant all privileges on mxonline.* to ‘mxonline‘@‘%‘ identified by ‘123456‘; flush privileges;
生成Django默认的数据表
使用pycharm Tools-->Run manage.py Task...
manage.py@mxonline> makemigrations manage.py@mxonline> migrate
查看mxonline,已经生成了表,如下:
mysql> show tables; +----------------------------+ | Tables_in_mxonline | +----------------------------+ | auth_group | | auth_group_permissions | | auth_permission | | auth_user | | auth_user_groups | | auth_user_user_permissions | | django_admin_log | | django_content_type | | django_migrations | | django_session | +----------------------------+