反映Postgresql现有数据库时出现RuntimeError

时间:2019-06-10 09:33:09

标签: sqlalchemy flask-sqlalchemy

我目前正在使用python脚本连接现有数据库。我试图使用反射方法。但是,尝试失败,并返回了RuntimeError。

engine = create_engine("some connection string")
meta = MetaData(engine)
meta.reflect()

预期结果应正常返回。但是,它返回运行时错误:

>>> meta.reflect()
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/engine/result.py", line 550, in __iter__
    raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/sql/schema.py", line 3329, in reflect
    bind.engine.table_names(schema, connection=conn))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1814, in table_names
    return self.dialect.get_table_names(conn, schema)
  File "<string>", line 2, in get_table_names
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/engine/reflection.py", line 42, in cache
    return fn(self, con, *args, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1970, in get_table_names
    return [row[0] for row in result]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1970, in <listcomp>
    return [row[0] for row in result]
RuntimeError: generator raised StopIteration

如何解决此问题?预先感谢!

0 个答案:

没有答案