0

我正在使用带有 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' ()
4

1 回答 1

2

It says it can't find the table teams- confirm with SqlLite ( I use firefox plugin) that it exists and that is the name. Also, copy the SQL in the error message in a Sqlite window and see if it runs.

于 2012-06-03T06:57:02.913 回答