我有一个继承的Pylons应用程序。它有一个MySQL数据库。应用程序中有一个名为Node的模型。我想首先列出数据库中的所有节点。然后,我希望能够添加一个节点。到目前为止,我一直在尝试:
import myapp.model as model
nodes = model.Session.query(model.Node).all()
for node in nodes:
print node
上面的代码抛出了我在其他问题中看到的错误,例如one:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py", line 1579, in all
return list(self)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py", line 1689, in __iter__
return self._execute_and_instances(context)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py", line 1694, in _execute_and_instances
mapper=self._mapper_zero_or_none())
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py", line 717, in execute
engine = self.get_bind(mapper, clause=clause, **kw)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py", line 851, in get_bind
raise sa_exc.UnboundExecutionError(
sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on mapper Mapper|Node|node, SQL expression or this Session
我觉得我错过了一步或什么的。我习惯于在Django中使用模型,这是我第一次使用Pylon应用程序。我认为这与Sessions有关,但我不确定。有谁知道如何列出所有节点,然后添加节点?