zoukankan      html  css  js  c++  java
  • django 使用mysql数据库

     

     

    一 修改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

    百度之后发现 找到对应项目的 djangodbackendsmysqlase.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

    
    
  • 相关阅读:
    MyISAM 和 InnoDB 索引的区别
    iOS crash日志
    。。。
    redis的缓存测试
    job测试
    笔记
    Android获取启动页面Activity方法
    UI自动化框架-一个小demo
    mitmproxy-java 的尝试
    monkey
  • 原文地址:https://www.cnblogs.com/ZFBG/p/11277766.html
Copyright © 2011-2022 走看看