ZFBG

 

 

一 修改settings里面的配置文件

 

import pymysql         # 一定要添加这两行!通过pip install pymysql! 或者pycharm 里面安装
pymysql.install_as_MySQLdb()
DATABASES = {
    \'default\': {
        \'ENGINE\': \'django.db.backends.mysql\',
        \'NAME\': \'mysite2\',
        \'USER\':\'root\',
        \'PASSWORD\':\'2GXXXXl\',
        \'HOST\':\'39.108.113.213\',
        \'PORT\':\'3306\',
    }
}

二 报错

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

百度之后发现 找到对应项目的 django\db\backends\mysql\base.py文件

注释

if version < (1, 3, 3):
    raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)

例如

 

启动后又报错

django.db.utils.InternalError: (1049, "Unknown database \'mysite2\'")   使用mysql数据库需要手动创建数据库

 

 重启继续报错

AttributeError: \'str\' object has no attribute \'decode\'

 

顺着报错文件点进去,找到query = query.decode(errors=‘replace’)
将decode修改为encode即可

 

 正常

继续报错

django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server ve

原因:django2.1 版本不再支持mysql5.5


分类:

技术点:

相关文章:

  • 2022-01-20
  • 2021-04-29
  • 2021-06-16
  • 2022-12-23
  • 2021-10-06
  • 2021-11-28
猜你喜欢
  • 2022-01-07
  • 2021-04-30
  • 2021-11-23
  • 2021-12-03
  • 2021-11-18
相关资源
相似解决方案