settings.py文件下的database设置:
~~~
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_db',
'USER': 'root',
'PASSWORD': '1234',
# 'HOST': '',
# 'PORT': '',
}
}
~~~
__init__.py下的设置:
~~~
import pymysql
pymysql. install_as_MySQLdb()
~~~
同步数据库:
按键
Tools->Run manage.py Task...
输入命令行:
~~~
makemigrations
migrate
~~~
ORM语句,等于mysql语句的封装:
![](https://box.kancloud.cn/261d090c1000866599cbfcd6ce1c4f75_395x282.png)