我在sqlalchemy中使用sqlite:
执行此命令时:
engine.execute("select * from teams");
<sqlalchemy.engine.base.ResultProxy object at 0x245b190>
因此,它可以返回引用
我有一个包含Team类的.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' ()
答案 0 :(得分:2)
它说无法找到表团队 - 用SqlLite(我使用firefox插件)确认它存在,这就是名称。另外,在Sqlite窗口中复制错误消息中的SQL,看看它是否运行。