1

我正在尝试自动生成用于 SQLalchemy 的模式,我正在使用 sqlautocode 来执行此操作,我使用以下命令

D:~ admin$ sqlautocode mysql://'user':"pass"@xx.xx.xx.xx:3306/db_name -o tables.py

但我不断收到以下错误..

Traceback (most recent call last):
  File "/usr/local/bin/sqlautocode", line 9, in <module>
load_entry_point('sqlautocode==0.7', 'console_scripts', 'sqlautocode')()
  File "/Library/Python/2.7/site-packages/distribute-0.6.45-py2.7.egg/pkg_resources.py", line 343, in load_entry_point
  return get_distribution(dist).load_entry_point(group, name)
  File "/Library/Python/2.7/site-packages/distribute-0.6.45-py2.7.egg/pkg_resources.py", line 2354, in load_entry_point
return ep.load()
  File "/Library/Python/2.7/site-packages/distribute-0.6.45-py2.7.egg/pkg_resources.py", line 2060, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
 File "/Library/Python/2.7/site-packages/sqlautocode/main.py", line 4, in <module>
from declarative import ModelFactory
 File "/Library/Python/2.7/site-packages/sqlautocode/declarative.py", line 17, in <module>
from sqlalchemy.ext.declarative import _deferred_relation as _deferred_relationship
ImportError: cannot import name _deferred_relation

https://pypi.python.org/pypi/sqlautocode

4

2 回答 2

3

改用sqlacodegen

D:~ admin$ sqlacodegen mysql://'users':"pass"@xx.xx.xx.xx:3306/db_name --outfile tables.py

于 2014-07-21T18:18:01.383 回答
0

这是因为您的 sqlalchemy 版本高于 07。
在 C:\Python27\Lib\site-packages\sqlautocode 中找到 declarative.py

从 sqlalchemy.ext.declarative 导入 _deferred_relationship 更改为从 sqlalchemy.ext.declarative.clsregistry 导入 _deferred_relationship

这项工作在我的工作中。

于 2017-11-09T07:17:32.460 回答