私はsqlalchemyでsqliteを使用しています:
このコマンドを実行すると:
engine.execute("select * from teams");
<sqlalchemy.engine.base.ResultProxy object at 0x245b190>
したがって、参照を返すときに機能します
チームチームを含む.pyファイルがあります。
class Team(Base):
__tablename__ = 'teams'
id = Column(Integer,autoincrement=False, primary_key=True)
name = Column(String(255))
flag = Column(String(255))
url = Column(String(255))
チームをインポートしますfrom classes import
しかし、ORMを使用しようとすると、次のエラーが発生します。
for instance in session.query(Team):
... print instance.id
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/orm/query.py", line 2224, in __iter__
return self._execute_and_instances(context)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/orm/query.py", line 2239, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1450, in execute
params)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1583, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1697, in _execute_context
context)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1690, in _execute_context
context)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/default.py", line 331, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (OperationalError) no such table: teams u'SELECT teams.id AS teams_id, teams.name AS teams_name, teams.flag AS teams_flag, teams.url AS teams_url \nFROM teams' ()