我发现MySQL数据库无法正常启动,所以我卸载了Mysql 5.7。我安装了MySQL 8.0.21,我发现我的Django项目有问题。我想在我的 Django 项目上进行 makemigrations,然后我的 Django 项目出现错误。请帮忙,我不知道如何解决这个错误。包Django==2.1.5mod-wsgi==4.7.1mysql-connector-python==8.0.21mysqlclient==2.0.1Python 3.7.9MySQL Ver 8.0.21Setting.pyDATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'HOST': 'xxxxxx.compute.amazonaws.com', 'PORT': '3306', 'NAME': 'xxxxx', 'USER': 'xxxxx', 'PASSWORD': 'xxxxxx', 'init_command': "SET sql_modes = 'STRICT_TRANS_TABLES'", },}python3 manage.py makemigrations
3 回答
![?](http://img1.sycdn.imooc.com/545864190001966102200220-100-100.jpg)
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
将 MySQL 与 Django 结合使用的推荐方法是安装mysqlclient
而不是安装mysql-connector-python
.
如果您使用mysql-connector-python
,那么您需要在 DATABASES 设置中将 更改为。'mysql.connector.django'
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'HOST': 'xxxxxx.compute.amazonaws.com',
'PORT': '3306',
'NAME': 'xxxxx',
'USER': 'xxxxx',
'PASSWORD': 'xxxxxx',
'init_command': "SET sql_modes = 'STRICT_TRANS_TABLES'",
},
}
![?](http://img1.sycdn.imooc.com/5333a1920001d36402200220-100-100.jpg)
BIG阳
源代码
TA贡献1859条经验 获得超6个赞
pip install PyMySQL
Django:设置.py
import pymysql pymysql.install_as_MySQLdb()
源代码pymysql.__init__.py
def install_as_MySQLdb(): """ After this function is called, any application that imports MySQLdb or _mysql will unwittingly actually use pymysql. """ sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"]
![?](http://img1.sycdn.imooc.com/5458692c00014e9b02200220-100-100.jpg)
慕码人8056858
TA贡献1803条经验 获得超6个赞
你需要通过在ubuntu上运行它来安装缺少的pkg,然后重新启动mysql
sudo apt-get install libmysqlclient-dev python-dev sudo /etc/init.d/mysql restart
添加回答
举报
0/150
提交
取消