mysql - 使用pwiz从mysql生成peewee模型时出现AttributeError

标签 mysql python-2.7 ubuntu

当我运行 pwiz 从现有数据库生成 peewee 调制解调器时,它显示以下错误:

root@server:~# python -m pwiz -e mysql  -P  -H 127.0.0.1 mysql
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/pwiz.py", line 202, in <module>
    print_models(introspector, tables, preserve_order=options.preserve_order)
  File "/usr/local/lib/python2.7/dist-packages/pwiz.py", line 47, in print_models
    database = introspector.introspect(table_names=tables)
  File "/usr/local/lib/python2.7/dist-packages/playhouse/reflection.py", line 440, in introspect
    tables = self.metadata.database.get_tables()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3089, in get_tables
    return [table for table, in self.execute_sql('SHOW TABLES')]
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2459, in execute_sql
    cursor = self.cursor(commit)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2445, in cursor
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2411, in connect
    self._state.set_connection(self._connect())
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3083, in _connect
    return mysql.connect(db=self.database, **self.connect_params)
AttributeError: 'NoneType' object has no attribute 'connect'

问题是什么?数据库用户名和密码正确。

最佳答案

PyMySql 未安装。使用 pip 或其他可用选项安装它:

pip install PyMySql

很遗憾,peewee的依赖列表中没有写`python的PyMySql1模块,需要单独安装。

关于mysql - 使用pwiz从mysql生成peewee模型时出现AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48541194/

相关文章:

mysql - MySQL innoDB 更新缓慢(无知)

php - XAMPP 的远程共享文件夹?

传递字符串时PHP MySQL查询错误

linux - DBus.ObjectManager.GetManagedObjects 中缺少 LEAdvertisingManager1

c++ - valgrind 不正确的输出位置

mysql - 在mysql中一起查询where,having和order by

python - 对Python整数的最后6k位进行base64编码的最佳方法

python - 我的抓取工具产生了太多的项目,而不是将它们全部合并成一小堆

python - 如何在 Ubuntu 16.04 上安装 python-gasp?

linux - Bash - if 语句不会自动运行