本文详细介绍PyMySQL搭建数据库
安装 PyMySQL
- http://www.cnblogs.com/sshoub/p/4321640.html 详细安装教程
- https://jingyan.baidu.com/article/f96699bbaa8fc1894f3c1b5a.html 详细卸载教程
-
pip install PyMySQL
创建数据库
-
CREATE DATABASE guest CHARACTER SET utf8;
-
Python3 不支持Mysql,需要Pymyql引导
-
重新同步数据库
manage.py migrate
cmd命令行操作数据库
F:
cd F:\workspace\guest
manage.py shell
- 插入数据--创建发布会表
from datetime import datetime
# 创建发布会表
Event.objects.create(id=5,name='联想发布会',limit=1800,status=True,address='南京博物馆',start_time=datetime(2018,10,24,14,0,0))
Event.objects.create(id=4,name='华为发布会',limit=2500,status=True,address='苏州博物馆',start_time=datetime(2017,10,24,14,0,0))
Event.objects.create(id=3,name='ViVo发布会',limit=2000,status=True,address='苏州通园路188号',start_time=datetime(2017,11,24,14,0,0))
Event.objects.create(id=2,name='魅族发布会',limit=3000,status=True,address='北京怀柔博远路78号',start_time=datetime(2017,12,24,14,0,0))
Event.objects.create(id=1,name='小米发布会',limit=1500,status=True,address='苏州园区',start_time=datetime(2017,10,30,14,0,0))
- 插入数据--创建嘉宾表
Guest.objects.create(realname='李明成',phone=18125141234,email='[email protected]',sign=True,event_id=5)
Guest.objects.create(realname='武嘉程',phone=18625141234,email='[email protected]',sign=True,event_id=4)
Guest.objects.create(realname='张婉仪',phone=13064937058,email='[email protected]',sign=True,event_id=3)
Guest.objects.create(realname='许水心',phone=17767267412,email='[email protected]',sign=True,event_id=2)
Guest.objects.create(realname='张亚磊',phone=15050488662,email='[email protected]',sign=True,event_id=1)
- 查询数据
from sign.models import Event,Guest
查询发布会表、嘉宾表
Event.objects.all()
Guest.objects.all()
使用Navicat连接MySQL
-
发布会表、嘉宾表
更换了数据库重新创建后台账号
manage.py createsuperuser 后台创建管理员账号 admin 1234asdf