python3 -m pip install PyMySQL
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'school',
'USER': 'school',
'PASSWORD': 'aa1231230',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
python manage.py makemigrations
python manage.py migrate
安装mysqlclient
官网文档
macOS (Homebrew)
Install MySQL and mysqlclient:
# Assume you are activating Python 3 venv
$ brew install mysql pkg-config
$ pip install mysqlclient
2.Django配置
import pymysql
pymysql.install_as_MySQLdb()
检查权限问题