Maison  >  Questions et réponses  >  le corps du texte

python - sqlalchemy中,query出来的实体,在使用的实体的属性时还是需要连接数据库么?

比如我已经用session的query查询出TestModel了,查询出了所有的结果 all()
返回的结果集放到一个list(TestList)。
其中TestModel有一个属性是Name, 我在遍历TestList时,读取属性Name,会提示

Exception Instance <TestModel at 0x2675433ff28> is not bound to a Session; 
attribute refresh operation cannot proceed

那么各位是怎么处理的呢?

巴扎黑巴扎黑2741 Il y a quelques jours447

répondre à tous(1)je répondrai

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:33:50

    Résolu, mais un peu confus.
    La solution est d'ajouter la méthode __repr__ dans le modèle

    répondre
    0
  • Annulerrépondre