zoukankan      html  css  js  c++  java
  • Pycharm添加Mysql數據庫的坑

    1.Did you install mysqlclient?

    解决方法:
    Django连接MySQL时默认使用MySQLdb驱动,但MySQLdb不支持Python3,因此这里将MySQL驱动设置为pymysql,使用 pip install pymysql 进行安装,然后在工程文件__init__.py添加以下代码即可。

    #安装pymysql
    pip install pymysql
    #__init__.py
    import pymysql
    pymysql.install_as_MySQLdb()

    第一种:
    django降到2.1.4版本就OK了

    第二种(仍使用django 2.2版本):

    #找到Python环境下 django包,并进入到backends下的mysql文件夹
    cd /opt/anaconda3/envs/envAGC_Mini/lib/python3.6/site-packages/django/db/backends/mysql
    #文件列表如下

    # 找到base.py文件,注释掉 base.py 中如下部分(35/36行)
    if version < (1, 3, 3):
         raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)

    此时仍会会报错,报错信息如下:

    AttributeError: ‘str’ object has no attribute ‘decode’

    #找到operations.py文件(146行),将decode改为encode
    #linux vim 查找快捷键:?decode
    if query is not None:
        query = query.decode(errors='replace')
    return query
    #改为
    if query is not None:
        query = query.encode(errors='replace')
    return query

    實測該方法是可以的


    2.添加數據庫後,pycharm裡面顯示的數據庫不完整或不正確,顯示不知是什麼東西
    右擊數據庫名字-> Database Tools -> Manage Shown Schames
    裡面可以選擇顯示的數據庫
  • 相关阅读:
    Nodejs读取文件时相对路径的正确写法(使用fs模块)
    node 读取多个文件、合并多个文件、读写多个文件
    js中typeof用法详细介绍
    express源码分析之Router
    14 Django的用户认证组件
    13-1 jquery操作cookie
    13 Django组件- cookie与session
    12 Django组件-form组件
    11 Django组件-分页器
    10 Django与Ajax
  • 原文地址:https://www.cnblogs.com/tyh-tesla/p/11337365.html
Copyright © 2011-2022 走看看