我目前正在使用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
如何解决此问题?预先感谢!