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

    
    
  • 相关阅读:
    上下文管理
    复习1
    描述符
    迭代器斐波那契数列
    迭代器协议
    __call__ 方法
    析构方法__del__
    __module__和class
    1.8命令执行顺序控制与管道(学习过程)
    1.7文件系统操作与磁盘管理(学习过程)
  • 原文地址:https://www.cnblogs.com/ZFBG/p/11277766.html
Copyright © 2011-2022 走看看